我一直在尝试计算如何将queuecomplete回调选项添加到dropzone.js。我读了dropzone.js - how to do something after ALL files are uploaded但它显示了几个选项,但我不明白在哪里/如何实现它。我尝试在dropzone.js的引用之后添加代码,在dropzone.js等中没有运气。我只是想用dropzone类的最小形式来简化它。
我试过了:
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。
我想我只需要知道如何实现它。
答案 0 :(得分:1)
您必须先添加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,它没有给出错误(你不能在stackoverflow上传,因为动作不存在)
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 */ });
内添加代码。