如果队列中至少有 10 个文件,如何设置 dropzone 上传?

Joh*_*ins 1 minimum limit dropzone.js

如果队列中至少有 10 个文件,如何设置 dropzone 上传?

我已将 autoProcessQueue 设置为 false,这样当单击提交按钮时,将运行一个函数来检查排队的文件。如果它们小于或大于 10,则不会上传。

我该如何实现这一目标?请协助。

我在谷歌上到处搜索,但似乎找不到答案。。请协助!

这是我的代码..

<html>

<head>
<title></title>
<script src="ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">   </script>
<link href="css/basic.css" rel="stylesheet" type="text/css" />
</head>


<body>
<form role= "form"></form>
<button id="submit-all">Submit all files</button>
</body>

<script>
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.on("maxfilesexceeded", function(file) { this.removeFile(file); });


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

}
};
</script>
</html>
Run Code Online (Sandbox Code Playgroud)

wal*_*876 5

您可以使用 dropzone 中的方法在 init 函数内完成此操作getQueuedFiles()

Dropzone.autoDiscover = false;

Dropzone.options.myDropzone = {
    autoProcessQueue: false,
    init: function () {
        var submitButton = document.querySelector("#submit-all");
        myDropzone = this;
        submitButton.addEventListener("click", function () {
            if (myDropzone.getQueuedFiles().length >= 10) { 
                myDropzone.processQueue();
            }
            else {
                alert("Not enough files!");
            }
        });
    }
};

var myDropzone = new Dropzone('form#my-dropzone');
Run Code Online (Sandbox Code Playgroud)