以下代码下载多个文件,但进度条未更新。如果我删除循环并仅下载一个文件,它会更新。甚至进度条以前也可以用于多个文件,但不知道我现在做错了什么。我也试过把 var fileTransfer = new FileTransfer(); 外环
for(i=0;i<lesson_audio.length;i++){
var fileTransfer = new FileTransfer();
var filePath = fs_path+"/"+lesson_audio[i];
var uri = encodeURI("http://myurl/"+lesson_audio[i]);
fileTransfer.onprogress = function(progressEvent) {
perc = Math.floor((progressEvent.loaded / progressEvent.total) * 100);
$('#progress-bar').val(perc);
$('#progress-bar').slider('refresh');
}
fileTransfer.download(
uri,
filePath,
function(entry) {
$("#progress-text").html($("#progress-text").html() + "download complete:" + entry.fullPath + "\n");
},
function(error) {
$("#progress-text").html($("#progress-text").html() + "download error:" + error.source + "\n")
}
);
}