我正在使用dropzone.js构建拖放文件上传。第一次上载文件时,maxFiles
配置选项效果很好。但是,当我显示已经上传的文件并尝试再次上传时,maxFiles
配置将被忽略。
我正在显示已上传的文件,如下所示:
init: function() {
var thisDropzone = this;
track = getParameterByName('trackno');
$.getJSON('get_upload_files.php?track='+track, function(data) { // get the json response
$.each(data, function(key,value){ //loop through it
var mockFile = { name: value.name, size: value.size }; // here we get the file name and size as response
thisDropzone.options.thumbnail.call(thisDropzone, mockFile, "uploads/"+value.name);//uploadsfolder is the folder where you have all those uploaded files
thisDropzone.emit("addedfile", mockFile);
});
});
}
最佳答案
一旦知道已经上传了多少文件,您可以做的就是更新option.maxFiles
值。
假设您最多需要10个文件,它看起来像:
init: function() {
var thisDropzone = this;
track = getParameterByName('trackno');
$.getJSON('get_upload_files.php?track='+track, function(data) { // get the json response
$.each(data, function(key,value){ //loop through it
var mockFile = { name: value.name, size: value.size }; // here we get the file name and size as response
thisDropzone.options.thumbnail.call(thisDropzone, mockFile, "uploads/"+value.name);//uploadsfolder is the folder where you have all those uploaded files
thisDropzone.emit("addedfile", mockFile);
});
// update maxFiles
thisDropzone.options.maxFiles = 10 - data.length;
});
}
关于javascript - Dropzone JS-maxFiles无法正常工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35588656/