【发布时间】:2013-03-23 06:14:23
【问题描述】:
for 循环不等待 winjs 承诺完成
for (var j = 0; j < magazineResult[0].data.length; j++) {
downRequest[0].data[j].COVER_PAGE_THUMB = parentUrl + eval(JSON.stringify(downRequest[0].data[j].COVER_PAGE_THUMB));
// Create a new download operation.
downloadFile(eval(magazineResult[0].data[j].COVER_PAGE_THUMB),eval(JSON.stringify(magazineResult[0].data[j].COVER_PAGE_THUMB)));
var url = downRequest[0].data[j].COVER_PAGE_THUMB;
var imgPath = downRequest[0].data[j].ISSUE_ID;
var imgExtension = url.substring(url.lastIndexOf('.') + 1);
var fileName = imgPath + "." + imgExtension;
var promise = Windows.Storage.ApplicationData.current.localFolder.createFileAsync(fileName, Windows.Storage.CreationCollisionOption.replaceExisting);
// Assign the completion handler function.
promise.done(function (newFile) {
MagazineDownLoad.downloadFile(url, fileName, j, newFile);
});
}
【问题讨论】:
-
WinJS 承诺在哪里?
-
我需要为 MagazineDownLoad.downloadFile 操作实现承诺。只有在此操作完成后for循环才会继续。如何在这里实现承诺..?
标签: microsoft-metro winjs