Dropzone js - maxFiles 不工作
Dropzone js - maxFiles not working
我正在使用 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;
});
}
我正在使用 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;
});
}