javascript Dropzone.js 在事件触发后删除文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22981714/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 00:07:04  来源:igfitidea点击:

Dropzone.js remove files after an event is fired

javascript

提问by Ruther Bergonia

so heres my code:

所以继承人我的代码:

 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.
});

} };

} };

how can I add removeAllfiles after clicking the upload button. thanks

单击上传按钮后如何添加 removeAllfiles。谢谢

回答by BenEgan1991

This should work:

这应该有效:

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();
      }
    });

  }

};

By using this.on("complete", function() { //Code to be executed });you are able to execute your code once the files have been uploaded. In your case, you can remove all of the files.

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