【问题标题】:Dropzone show files existDropzone 显示文件存在
【发布时间】:2014-03-26 08:19:41
【问题描述】:

我在我的网站 dropzone.js 上使用了一个问题,但它对我不起作用。我有2个问题。 JSON 工作正常。

  1. 在现有文件中我没有删除按钮
  2. 当我通过拖放上传文件时上传文件两次
var FormDropzone = function () {

$(function() {

    var projectID = $("#projectID").html();

    var myDropzone = new Dropzone("#my-dropzone");

    $.getJSON('http://'+window.location.hostname+'/project/getFile/'+projectID, function( json ) {

      for (var i = 0; i < json.length; i++) {

        var mockFile = { name: json[i].name, size: json[i].size };

        myDropzone.emit("addedfile", mockFile);

        myDropzone.emit("thumbnail", mockFile, "../../upload_files/project/1/"+json[i].name);

      };
    })

});

return {
    //main function to initiate the module
    init: function () {  

        Dropzone.options.myDropzone = {
            init: function() {

                this.on("success", function(file, serverFileName) {
                  FileList = {"serverFileName" : serverFileName, "fileName" : file.name };
                });

                this.on("addedfile", function(file) {

                    // Create the remove button
                    var removeButton = Dropzone.createElement("<button class='btn btn-sm btn-block'>Remove file</button>");

                    // Capture the Dropzone instance as closure.
                    var _this = this;

                    // Listen to the click event
                    removeButton.addEventListener("click", function(e) {
                      var projectID = $("#projectID").html();
                      // Make sure the button click doesn't submit the form:
                      e.preventDefault();
                      e.stopPropagation();
                      $.post( "http://"+window.location.hostname+"/project/deleteFile", { file_name: file.name, project_id: projectID, FileList : FileList["serverFileName"]});
                      // Remove the file preview.
                      _this.removeFile(file);
                    });

                    // Add the button to the file preview element.
                    file.previewElement.appendChild(removeButton);
                });

            }            
        }
    }
};
}();

【问题讨论】:

    标签: javascript jquery dropzone.js


    【解决方案1】:

    要添加删除按钮,您必须添加删除选项,即 addRemoveLinks : true 到 dropzone 对象。 就像这个:

    Dropzone.options.mysample = {
      paramName: "file", // The name that will be used to transfer the file
      maxFilesize: 1, // MB
      addRemoveLinks : true,   
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-01
      • 2016-11-28
      • 2016-06-13
      • 2021-07-31
      • 2022-12-20
      • 2015-10-08
      • 1970-01-01
      相关资源
      最近更新 更多