上传后,dropzone js重置预览

时间:2018-09-17 07:15:53

标签: javascript dropzone.js

上传成功后,我无法重置dropzone js预览。

Dropzone.options.myDropzone= {
    url: 'postupload.php',
    autoProcessQueue: false,
    uploadMultiple: false,
    parallelUploads: 5,
    maxFiles: 1,
    acceptedFiles: 'image/*',
    addRemoveLinks: false,
    init: function() {
        dzClosure = this; // Makes sure that 'this' is understood inside the functions below.

        // for Dropzone to process the queue (instead of default form behavior):
        document.getElementById("submit-all").addEventListener("click", function(e) {
            // Make sure that the form isn't actually being sent.
            e.preventDefault();
            e.stopPropagation();
            dzClosure.processQueue();
        });

        //send all the form data along with the files:
        this.on("sendingmultiple", function(data, xhr, formData) {
            formData.append("firstname", jQuery("#firstname").val());
            formData.append("lastname", jQuery("#lastname").val());

        });
    }
}

1 个答案:

答案 0 :(得分:0)

我也有同样的问题,但是我一直在玩一些代码,我想我可能有某种解决方案。它并没有像我希望的那样重新启动dropzone,但是它对用户的眼睛有些欺骗。

这将从预览中删除所有文件或图像,必须由“提交”按钮触发,而不是从服务器端删除图像。

$('div#animalImage')[0].dropzone.files.forEach(function (file) {
   file.previewElement.remove();
});
$('div#animalImage').removeClass('dz-started');

我希望它能给您一些起点。我也在等待更好的解决方案。

致谢