how can i reset dropzone by this code?

一笑奈何 提交于 2020-01-02 02:47:07

问题


Dropzone.options.imageFile = {
    url: HOST_NAME + USER_NAME + BUILDER_API +'image/',
    method: 'POST',
    // enter code here
    acceptedFiles: '.jpg, .jpeg, .png',
    paramName: "imagefile", // The name that will be used to transfer the file
    maxFilesize: 10, // MB
    //addRemoveLinks: true,
    maxFiles: 2,
    init: function() {
        this.on("success", function(file, response) {
            image_id = response.id;
            IMAGES.push(image_id);
            check_files();
        }),
        this.on("removedfile", function(file, response){
            data = JSON.parse(file.xhr.response);
            alert(data['id']);
        });
    },
};

What i need to do to reset dropzone completely?


回答1:


Not 100% sure I understood the question, but I presume you want to be able to reuse the dropzone instance from its original state.

Technically you want to call removeAllFiles() and that will remove all the files.

Here is an example that shows you how to add a remove all files with one button: Remove all files with one button

Also, there were other people trying to do the same thing that you are looking for: Reset dropzone to Pristine state




回答2:


This is the answer to that question and many like it on stackoverflow... to removeAllFiles on a NON-programmatically created dropzone (http://www.dropzonejs.com/#configuration), you'd execute (using the OP's ID):

 var myDropzone = Dropzone.forElement("#imageFile");
 myDropzone.removeAllFiles();

The problem is that this does NOT put the nice "upload an image here" message back for me - just leaves an inexplicable white box - one more step to fix that.

 $(".dz-message").removeClass("hidden");

That will show the original message.




回答3:


I create a button and put this code. when clicking on the button, it's hidden and your dropzone is seen like a page refresh.

$("#btn").click(function () {
    $('#btn').hide();
    $('.dropzone')[0].dropzone.files.forEach(function(file) {
        file.previewTemplate.remove();
    });

    $('.dropzone').removeClass('dz-started');
});


来源:https://stackoverflow.com/questions/21702526/how-can-i-reset-dropzone-by-this-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!