事件触发后,Dropzone.js会删除文件

时间:2014-04-10 07:42:30

标签: javascript

所以这是我的代码:

 Dropzone.options.myDropzone = {

  // Prevents Dropzone from uploading dropped files immediately
  autoProcessQueue: false,

  init: function() {
    var submitButton = document.querySelector("#submit-all")
        myDropzone = this; // closure

      submitButton.addEventListener("click", function() {
      myDropzone.processQueue(); // Tell Dropzone to process all queued files.
      myDropzone.removeAllFiles();
      console.log("a");

    });

// You might want to show the submit button only when 
// files are dropped here:
this.on("addedfile", function() {
  // Show submit button here and/or inform user to click it.
});

} };

如何在单击上传按钮后添加删除文件。感谢

1 个答案:

答案 0 :(得分:11)

这应该有效:

Dropzone.options.myDropzone = {

  autoProcessQueue: false,

  init: function() {
    var submitButton = document.querySelector("#submit-all")
        myDropzone = this;

    submitButton.addEventListener("click", function() {
      myDropzone.processQueue();
    });

    // Execute when file uploads are complete
    this.on("complete", function() {
      // If all files have been uploaded
      if (this.getQueuedFiles().length == 0 && this.getUploadingFiles().length == 0) {
        var _this = this;
        // Remove all files
        _this.removeAllFiles();
      }
    });

  }

};

使用this.on("complete", function() { //Code to be executed });,您可以在上传文件后执行代码。在您的情况下,您可以删除所有文件。