2015-11-18 43 views
1

如果只有最少10個文件在qeue上,我該如何設置dropzone上傳?如果只有最少10個文件位於qeue上,我如何設置dropzone上傳?

我已經設置了autoProcessQueue爲false,這樣當點擊提交按鈕時就會運行一個函數來檢查已編碼的文件。如果它們小於或大於10,則上傳不會發生。

如何存檔? 請協助。

我在谷歌搜索到處都是,但我似乎無法找到答案。 。請協助!

這裏是我的代碼..

<html> 

<head> 
<title></title> 
<script src="ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"> </script> 
<link href="css/basic.css" rel="stylesheet" type="text/css" /> 
</head> 


<body> 
<form role= "form"></form> 
<button id="submit-all">Submit all files</button> 
</body> 

<script> 
Dropzone.options.myDropzone = { 

// Prevents Dropzone from uploading dropped files immediately 
autoProcessQueue: false, 

init: function() { 
var submitButton = document.querySelector("#submit-all") 
myDropzone = this; // closure 

submitButton.addEventListener("click", function() { 

myDropzone.processQueue(); // Tell Dropzone to process all queued files. 



}); 

myDropzone.on("maxfilesexceeded", function(file) { this.removeFile(file); }); 


// You might want to show the submit button only when 
// files are dropped here: 
this.on("addedfile", function() { 
// Show submit button here and/or inform user to click it. 
}); 

} 
}; 
</script> 
</html> 

回答

1

您可以初始化函數內部使用該方法getQueuedFiles()從懸浮窗做到這一點:

Dropzone.autoDiscover = false; 

Dropzone.options.myDropzone = { 
    autoProcessQueue: false, 
    init: function() { 
     var submitButton = document.querySelector("#submit-all"); 
     myDropzone = this; 
     submitButton.addEventListener("click", function() { 
      if (myDropzone.getQueuedFiles().length >= 10) { 
       myDropzone.processQueue(); 
      } 
      else { 
       alert("Not enough files!"); 
      } 
     }); 
    } 
}; 

var myDropzone = new Dropzone('form#my-dropzone'); 
+0

謝謝你這麼much.Just正是我一直在尋找! –

相關問題