以编程方式将以编程方式添加的文件删除到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 );

最佳答案

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 );

10-06 14:28