将 queuecomplete 添加到 dropzone.js

Adding queuecomplete to dropzone.js

我一直在想办法将 queuecomplete 回调选项添加到 dropzone.js。我读了 dropzone.js - how to do something after ALL files are uploaded 但它显示了几个选项,但我不明白 where/how 来实现它。我尝试在引用 dropzone.js 之后添加代码,在 dropzone.js 等中添加代码,但没有成功。我只是想用 dropzone class.

的最小形式让它变得简单

我试过了:

Dropzone.options.filedrop = {
  init: function () {
    this.on("complete", function (file) {
      if (this.getUploadingFiles().length === 0 && this.getQueuedFiles().length === 0) {
        doSomething();
      }
    });
  }
};

还有

this.on("queuecomplete", function (file) {
     alert("All files have uploaded ");
});

但不断收到 Dropzone is not defined。

我想我只需要知道如何实现它。

您必须先添加 JavaScript 文件,然后再添加您正在使用的脚本。

<script src="./path/to/dropzone.js"></script>
<script>
Dropzone.options.filedrop = {
  init: function () {
      this.on("queuecomplete", function (file) {
          alert("All files have uploaded ");
      });
  }
};
</script>

下面是一个没有给出错误的工作 snnipet(你不能在 Whosebug 上上传,因为该操作不存在)

Dropzone.options.filedrop = {
  init: function () {
      this.on("queuecomplete", function (file) {
          alert("All files have uploaded ");
      });
  }
};
<script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/4.0.1/dropzone.js"></script>
<link rel="stylesheet" href="https://rawgit.com/enyo/dropzone/master/dist/dropzone.css">


<p>
  This is the most minimal example of Dropzone. The upload in this example
  doesn't work, because there is no actual server to handle the file upload.
</p>

<!-- Change /upload-target to your upload address -->
<form action="/upload-target" class="dropzone"></form>

注意:如果你使用jQuery你可以在$(document).ready(function { /* add here */ });.

里面添加代码