Is there a way to do drag-and-drop re-ordering of the preview elements in a dropzone.js instance?

后端 未结 3 1040
情歌与酒
情歌与酒 2021-02-02 14:41

I have a dropzone.js instance on a web page with the following options:

autoProcessQueue:false
uploadMultiple:true
parallelUploads:20
maxFiles:20
3条回答
  •  后悔当初
    2021-02-02 15:31

    Besides the code from ralbatross you will need to set the order of the file queue of dropzone..

    Something like:

    $("#uploadzone").sortable({
        items: '.dz-preview',
        cursor: 'move',
        opacity: 0.5,
        containment: '#uploadzone',
        distance: 20,
        tolerance: 'pointer',
        stop: function () {
    
            var queue = uploadzone.files;
            $('#uploadzone .dz-preview .dz-filename [data-dz-name]').each(function (count, el) {           
                var name = el.getAttribute('data-name');
                queue.forEach(function(file) {
                   if (file.name === name) {
                        newQueue.push(file);
                   }
                });
            });
    
            uploadzone.files = newQueue;
    
        }
    });
    

    And remember that the file is processed async, i keep an hashtable for reference when the file is done and save the order at the end.

    It doesn't work with duplicate filenames

提交回复
热议问题