从Dropzone.js中删除所有手动添加的文件?

时间:2014-02-19 08:39:53

标签: javascript dropzone.js

以编程方式将删除的文件删除到Dropzone时出现未知问题。 这是我的代码不起作用:

// constructor - OK
docsDropzone = new Dropzone( "#docsUpload", {
    url: uploadUrl,
    addRemoveLinks: true,
    init: function() {
        this.on( 'removedfile', removedFileCallback );
    }
} );

// add file - OK
var mockFile = { name: 'test.jpg', size: 0 };
docsDropzone.emit( "addedfile", mockFile );
docsDropzone.emit( "thumbnail", mockFile, 'test.jpg' );

// remove files - NOT OK
docsDropzone.removeAllFiles( true );

1 个答案:

答案 0 :(得分:22)

addedfile函数未将文件添加到dropzone.files 所以必须手动添加:

// add file - OK
var mockFile = { name: 'test.jpg', size: 0, status: 'success' };
docsDropzone.emit( "addedfile", mockFile );
docsDropzone.emit( "thumbnail", mockFile, 'test.jpg' );
docsDropzone.files.push( mockFile ); // file must be added manually

// remove files - NOW OK
docsDropzone.removeAllFiles( true );