1 回答

TA貢獻(xiàn)1995條經(jīng)驗(yàn) 獲得超2個(gè)贊
我能夠自己解決這個(gè)問題。以下是方法(請(qǐng)注意,這需要一些修改才能適用于您自己的代碼,我不是純粹的復(fù)制和粘貼答案):
創(chuàng)建一個(gè)數(shù)組來保存一些數(shù)據(jù):
/** Files currently uploading */
const uploadQueue: any[] = [];
捕獲FileSuccess事件并添加它
// Check the size of the queue
if (uploadQueue.length < 20) {
const that = (uploadSuccessEvent.sender as any);
const module = that._module;
const upload = module.upload;
$(".k-file").each((i, x) => {
//console.log(i, x);
if (uploadQueue.length < 20) {
const fileEntry = $(x);
const started = fileEntry.is(".k-file-progress, .k-file-success, .k-file-error");
const hasValidationErrors = upload._filesContainValidationErrors(fileEntry.data("fileNames"));
if (!started && !hasValidationErrors) {
uploadQueue.push(fileEntry.data("fileNames")[0].uid);
//console.log("fileEntry", fileEntry.data("fileNames")[0].uid);
// Start the upload process
module.performUpload(fileEntry);
}
}
else { return; }
});
}
創(chuàng)建一個(gè)新函數(shù)來處理上傳隊(duì)列:
/**
* Adds the file to the upload queue and starts the upload.
* Other files will be loaded via the on success event.
* @param uploadSelectEvent Select event object.
*/
function queueUpload(uploadSelectEvent: kendo.ui.UploadSelectEvent) {
//console.log("uploadSelectEvent", uploadSelectEvent);
// Check the size of the queue
if (uploadQueue.length < 20) {
// Start the upload process
const that = (uploadSelectEvent.sender as any);
const module = that._module;
const upload = module.upload;
//uploadSelectEvent.files.forEach((file, i) => { console.log(i, file); if (uploadQueue.length < 20) { uploadQueue.push(file.uid); } });
$(".k-file").each((i, x) => {
//console.log(i, x);
if (uploadQueue.length < 20) {
const fileEntry = $(x);
const started = fileEntry.is(".k-file-progress, .k-file-success, .k-file-error");
const hasValidationErrors = upload._filesContainValidationErrors(fileEntry.data("fileNames"));
if (!started && !hasValidationErrors) {
uploadQueue.push(fileEntry.data("fileNames")[0].uid);
module.performUpload(fileEntry);
}
}
else { return; }
});
}
}
捕獲FileSelect事件并將事件傳遞給queueUpload.
最后,您應(yīng)該一次將并發(fā)上傳限制為 20 個(gè)。它仍然允許將 100 個(gè)或 1000 個(gè)文件拖入瀏覽器(它可能仍會(huì)鎖定一秒鐘),但一次最多只能創(chuàng)建 20 個(gè)連接。這可能不是最理想的代碼,但它適用于我的情況。
添加回答
舉報(bào)