我正在使用Backbone,所以在渲染中我设置了超时并触发了脚本,这工作正常,但我无法触发队列完成状态,因此我可以在我的视图中做出反应。
onRender: function() {
setTimeout(function() {
var myDropzone = $(".dropzone").dropzone({
paramName: 'file',
clickable: true,
maxFilesize: 1,
uploadMultiple: true,
parallelUploads: 1,
autoProcessQueue: false,
thumbnailWidth: 200,
thumbnailHeight: 200,
maxThumbnailFilesize: 3,
init: function() {
var totalFiles = 0,
completeFiles = 0;
this.on("addedfile", function(file) {
console.log('added');
totalFiles += 1;
});
this.on("removed file", function(file) {
console.log('removed');
totalFiles -= 1;
});
this.on("complete", function(file) {
console.log('complete');
completeFiles += 1;
if (completeFiles === totalFiles) {
console.log('done');
}
});
},
queuecomplete: function() {
console.log('queuecomplete');
},
accept: function(file, done) {
console.log('accept');
var imageType = file.type;
var imageHeight = file.height;
var imageWidth = file.width;
var reader = new FileReader();
reader.onload = handleReaderLoad;
reader.readAsDataURL(file);
function handleReaderLoad(evt) {
console.log('handleReaderLoad');
$.ajax({
method: "POST",
timeout: 5000,
url: "image",
data: {
'client': $('#client-upload option:selected').val(),
'height': imageHeight,
'width': imageWidth,
'type': file.type,
'base64': evt.target.result
},
});
}
done();
},
});
myDropzone.on("complete", function(file) {
console.log('complete');
});
}, 1000);
},
在控制台中上传两张图片:
added upload.js:40
accept upload.js:62
added upload.js:40
accept upload.js:62
x2 handleReaderLoad