dropzone.js - 上传所有文件后如何做某事 [英] dropzone.js - how to do something after ALL files are uploaded
问题描述
我使用dropzone.js作为拖放文件上传解决方案。在所有上传文件后,我遇到了需要调用函数的问题。在这种情况下,
I am using dropzone.js for my drag-drop file upload solution. I am stuck at something where I need to call a function after all the files are uploaded. In this case,
Dropzone.options.filedrop = {
maxFilesize: 4096,
init: function () {
this.on("complete", function (file) {
doSomething();
});
}
};
将为每个已上传的文件调用doSomething()。如何在上传所有文件后调用函数?
doSomething() will be called for each file that has been uploaded. How can I call a function after all the files are uploaded?
推荐答案
编辑:现在有了您可以使用的 queuecomplete
活动正是出于这个目的。
There is now a queuecomplete
event that you can use for exactly that purpose.
上一个答案:
Paul B.的回答有效,但更简单的方法是检查是否队列中仍有文件或文件完成时上传。这样您就不必自己跟踪文件:
Paul B.'s answer works, but an easier way to do so, is by checking if there are still files in the queue or uploading whenever a file completes. This way you don't have to keep track of the files yourself:
Dropzone.options.filedrop = {
init: function () {
this.on("complete", function (file) {
if (this.getUploadingFiles().length === 0 && this.getQueuedFiles().length === 0) {
doSomething();
}
});
}
};
这篇关于dropzone.js - 上传所有文件后如何做某事的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!