我正在使用 https://github.com/johnculviner/jquery.fileDownload下载一系列文件。似乎有效:
for (var index = 0; index < files.length; ++index) {
var file = files[index];
$.fileDownload(file)
.done(function() {
alert("Done " + file);
}
)
.fail(function() {
alert("Fail " + file);
}
);
}
如何一次下载 5 个文件的 block ? 文件正在下载,但暂时没有显示任何警报。所以我想我这里可能有问题。
例如,当尝试下载 100 个文件时,我想下载 5 个,然后再下载其他 5 个等,直到全部完成。这可能吗?
最佳答案
下载第一个文件
var firstfile = files[0]; //first file id
var downloadresult = downloadFileEx(firstfile);
然后用jquery then链接其他文件 并使用 array.slice挑选大块
var begin=1; // start from second file
var end=5;
do {
for (var index = begin; index < files.slice(begin, end).length; i++) {
var file = files[index];
(function (index) {
downloadresult = downloadresult.then(function() {
return downloadFileEx(array[index]);
});
}(index));
}
index++;
}
begin = begin +5;
end = end + 5;
}
while (end < files.length);
编写文件下载函数
function downloadFileEx(file) {
return $.fileDownload(file)
.done(function() {
alert("Done " + file); // remove this 100 alerts will be blocked by browser, maintain an array of files
}
)
.fail(function() {
alert("Fail " + file);
}
);
}
关于javascript - jquery文件下载: download multiple files into chunks,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42904445/