0
我需要ajax同步工作,並且只有在所有下載完成時才顯示console.log('Downloads finalized!');
,但count++
在fileTransfer.download
函數中不起作用。爲什麼?科爾多瓦插件計數++
我的代碼:
function getdata()
{
var fileTransfer = new FileTransfer();
var path = cordova.file.dataDirectory;
jQuery.getJSON(MyJSONData, function(data) {
var count = 0;
jQuery.each(data, function(key, val) {
fileTransfer.download(
MyFileURL,
path+"data/images/"+key+".jpg",
function(theFile) {
console.log('Saved');
count++;
}, null
);
});
while(1)
{
if(count == Object.keys(data).length)
{
console.log('Downloads finalized!');
break;
}
}
}).fail(function() {
console.log('Error');
});
}