Javascript init中的DropZone替换映像

Javascript init中的DropZone替换映像,javascript,jquery,dropzone.js,Javascript,Jquery,Dropzone.js,我使用这段代码在init中从数据库上传图像。现在我想在上传新图像时删除这个初始图像 var o = $("div#uploader").dropzone({ url: "../../Merchant/UploadLogo", paramName: "logo", maxFiles: 1, //enqueueForUpload: false, maxfilesexceeded

我使用这段代码在init中从数据库上传图像。现在我想在上传新图像时删除这个初始图像

 var o = $("div#uploader").dropzone({
            url: "../../Merchant/UploadLogo",
            paramName: "logo",
            maxFiles: 1,

            //enqueueForUpload: false,
            maxfilesexceeded: function (file) {
                this.removeAllFiles();
                this.addFile(file);
            },

            addRemoveLinks: true,
            uploadMultiple: false,
            dictRemoveFile: "حذف",

            removedfile: function(file) {
                RemoveFile("Logo");
                var _ref;
                return (_ref = file.previewElement) != null ? _ref.parentNode.removeChild(file.previewElement) : void 0;
            },

            init: function() {

                var mockFile = { name: "avatar1.jpg", size: 12345, type: 'image/jpeg', url: "../../Merchant/GetLogo" };
                this.options.addedfile.call(this, mockFile);
                this.options.thumbnail.call(this, mockFile, mockFile.url);//uploadsfolder is the folder where you have all those uploaded files
            }

        });

我假设您希望在成功上载新图像时替换
Dropzone
中的旧图像。您可以通过组合
this.on('success')
this.removeFile
方法来实现这一点,这些方法由
Dropzone
提供:

Dropzone.options.myDropzone = {
    init: function() {
        this.on('success', function(file, message) {
            if (this.files.length > 1) {
                this.removeFile(this.files[0]);
            }
        });

        // ...
    }
};
要使其工作,还必须将您的
mockFile
注册为Dropzone的一个文件。要做到这一点,您可以在显示它之后立即将它推入
init
中的
this.files
数组中:

// Create and Display Mock File
var mockFile = { name: "avatar1.jpg", size: 12345, url: '/image.png' };
this.options.addedfile.call(this, mockFile);
this.options.thumbnail.call(this, mockFile, mockFile.url);

// Register it
this.files = [mockFile];

来源: ,
体验

Awesome,这正是通过
maxFiles
将上传限制为一个文件应该做的(但做得不正确)。