关闭按钮上的Dropzone' Save'点击

时间:2015-10-06 10:33:51

标签: javascript dropzone.js

enter image description here

我使用Dropzone插件上传图片,我遇到了一些问题。点击“保存'按钮,文件POST到服务器,但弹出窗口仍显示在浏览器中。所以,我想知道,如果这是正常的插件行为,如果不是,我是否可以在“保存”上收听点击事件。按钮,然后关闭弹出窗口?

EDITED

我的HTML

<div class="modal resource-creator-modal" tabindex="-1">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title">Edit Resource</h4>
            </div>
            <div class="modal-body">

            </div>
            <div class="modal-footer">
                <button form="resource-creator" type="reset" class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
                <button form="resource-creator" type="submit" class="btn btn-success" data-loading-text="Proceed...">Save</button>
            </div>
        </div>
    </div>
</div>

Dropzone的初始化

initFileUpload: function() {
    if (this.dropzone) return;

    this.dropzone = new Dropzone(this.$('.dropzone-box').get(0), {
        url: this.options.url.fileUpload,


addRemoveLinks : true,
            maxFiles: 1,
            acceptedFiles: '.jpg, .mp4',
            dictResponseError: "Can't upload file!",
            thumbnailWidth: 138,
            thumbnailHeight: 120,

            previewTemplate: $('#drop-item-preview').html()
        });

        this.dropzone.on('complete', this._onUploadFileComplete.bind(this));
    }

1 个答案:

答案 0 :(得分:2)

由于您无法发布与上传者相关的完整代码,因此无法根据您的上传者提供解决方案。但是,如果你理解下面的代码,你将能够实现你想要的。

this.on("complete", function (file) {
    if (this.getUploadingFiles().length === 0 && this.getQueuedFiles().length === 0) {
        // Some options to hide the Container or Modal
        $('#file-uploader-container').hide(); // If the uploader is in a Container hide it
        $('#file-uploader-modal').hide(); //If your uploader is in a Bootstrap modal, hide it by applying Display none on the Modal.
        $('#file-uploader-modal').modal('hide'); //By closing modal programmatically. 
        $('#file-uploader-modal #btn-close').trigger('click');  // By triggering Modal's close button (give an ID to call it)
    }
});

根据您的需要,在容器或模态上应用脚本。希望它能解决你的问题。