0

I have a select option element in my project with two options, books and images. For book option, I want to allow only single file to upload. But for images option I need to allow multiple file selection. I am trying to this way but not succeeded:

 Dropzone.options.frmMediaDropzone = {
   maxFilesize: 99,
   acceptedFiles: ".jpeg,.jpg,.png,.gif,.pdf",
   parallelUploads: 1,
   addRemoveLinks: true,
   maxFiles: 100,
   init: function() {
     myDropzone = this;
     this.on("removedfile", function(file) {
       console.log(file);
     });

     this.on("success", function(file, response) {
       console.log(response.imageName);
     });
   }
 };

On option change, I am trying this:

Dropzone.options.frmMediaDropzone.maxFiles = 1;

But its not working. If anyone has idea please help.

4

2 回答 2

1

试试这个方法来解决你的问题,

你需要在javascript中定义一个变量。

var myDropZone;

myDropZoneinit()事件中初始化变量。

init: function() {

    myDropzone = this;
}

myDropzone 变得可访问,因此声明

myDropzone.options.maxFiles = 1;

clickable:false文件上传完成后设置,

myDropzone.options.clickable = false;

超过最大文件限制后手动删除文件。

myDropzone.on("maxfilesexceeded", function(file) {
    myDropzone.removeFile(file);
});
于 2018-03-07T04:42:24.010 回答
0

有两种方法可以做到这一点。您可以动态创建您的 dropzone,然后使用 .attr 更改它的属性,或者在定义 dropzone 时在您的 init 属性中创建一个侦听器事件。

有关类似示例,请参见此链接(参见第二个答案): Dropzone: change acceptedFiles dynamic

于 2018-03-07T04:45:55.910 回答