2014-02-24 2 views
0

У меня есть проблема, которую я использую на моем сайте dropzone.js, но это не работает хорошо для меня. У меня 2 проблемы. JSON отлично работает.Есть файлы демонстрации Dropzone

  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); 
       }); 

      }    
     } 
    } 
}; 
}(); 

ответ

0

Для добавления кнопки вы должны добавить удалить опцию т.е. addRemoveLinks : true удалить к объекту dropzone. точно так же, как этот:

Dropzone.options.mysample = { 
    paramName: "file", // The name that will be used to transfer the file 
    maxFilesize: 1, // MB 
    addRemoveLinks : true, 
}; 
Смежные вопросы