【问题标题】:dropzone action after all files are uploaded上传所有文件后的 dropzone 操作
【发布时间】:2014-04-04 20:51:20
【问题描述】:

我是这样使用 dropzonejs 的:

<script type="text/javascript">
        jQuery(function($) {
            try 
            {
                $(".dropzone").dropzone({
                    paramName: "file", // The name that will be used to transfer the file
                    maxFilesize: 0.5, // MB
                    uploadMultiple: true,
                    //addRemoveLinks : true,
                    dictDefaultMessage :
                        '<span class="bigger-150 bolder"><i class="icon-caret-right red"></i> Drop files</span> to upload \
                        <span class="smaller-80 grey">(or click)</span> <br /> \
                        <i class="upload-icon icon-cloud-upload blue icon-3x"></i>',
                    dictResponseError: 'Error while uploading file!',               
                    //change the previewTemplate to use Bootstrap progress bars
                    previewTemplate: "<div class=\"dz-preview dz-file-preview\">\n  <div class=\"dz-details\">\n    <div class=\"dz-filename\"><span data-dz-name></span></div>\n    <div class=\"dz-size\" data-dz-size></div>\n    <img data-dz-thumbnail />\n  </div>\n  <div class=\"progress progress-small progress-striped active\"><div class=\"progress-bar progress-bar-success\" data-dz-uploadprogress></div></div>\n  <div class=\"dz-success-mark\"><span></span></div>\n  <div class=\"dz-error-mark\"><span></span></div>\n  <div class=\"dz-error-message\"><span data-dz-errormessage></span></div>\n</div>"
                });
            } 
            catch(e) 
            {
                alert('Dropzone.js does not support older browsers!');
            }
});

    </script>

上传所有文件后,我究竟可以在哪里让监听器做某事(重新加载/重定向/警报)?

【问题讨论】:

    标签: javascript dropzone.js


    【解决方案1】:

    这是一个使用 jQuery for Dropzone 的通用初始化脚本

    Dropzone.options.myDropZoneForm = {
        url: 'url/here',
        autoProcessQueue: false,
        uploadMultiple: true,
        parallelUploads: 100,       
        addRemoveLinks: true,
        uploadMultiple: true,
        acceptedFiles: 'image/*, audio/*, video/*',
        maxFiles: 10,
        init: function () {
            var thisDropzone = this;
    
            // just showing some dropped files stats
            var totalFiles = 0, completeFiles = 0;
            this.on('addedfile', function(file){
                totalFiles += 1;
                totalFilesFormatted = totalFiles.toFixed(2);
                $('#showTotalFileCount').html(totalFilesFormatted);
            });
            this.on('removedfile', function(file){
                totalFiles -= 1;
                totalFilesFormatted = totalFiles.toFixed(2);
                $('#showTotalFileCount').html(totalFilesFormatted);
            });
            this.on('maxfilesreached', function(file){
                alert('maxFiles reached');
            });
            this.on('maxfilesexceeded', function(file){
                alert('files dropped exceeded maxFiles');
            });
            this.on("sendingmultiple", function(){
                // event when files are being sent
            });
            this.on("successmultiple", function(files, response) {
                // event when files are successfully uploaded
                // you can return a response string and process it here through 'response'
            });
            this.on("errormultiple", function(files, response) {
              // event when there's an error
            });
        }
    }
    

    希望这可以帮助您解决问题。干杯!

    【讨论】:

    • 谢谢,对我帮助很大
    【解决方案2】:

    您需要参数completemultiple,这是一个将在所有文件上传后调用的函数。

    您也感兴趣:

    • processingmultiple
    • sendingmultiple
    • successmultiple
    • canceledmultiple

    发件人:http://www.dropzonejs.com/

    【讨论】:

    • 你能给我举个例子吗?我尝试过这种方式,但它不起作用: init: function() { this.on("completemultiple", function(file) { alert("Added file."); }); },
    • 所以您没有看到警报?你能检查以确保你有最新的 dropzone JS 吗?将 completemultiple 参数与 paramName 等其他 dropzone 参数一起添加。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-12
    • 1970-01-01
    • 2020-09-04
    相关资源
    最近更新 更多