在下面的函数中,createPromiseToUpdateStoreToCategoryMapObject
是一个返回promise的函数。
如果我发表评论listOfPromises.push( createPromiseToUpdateStoreToCategoryMapObject( storeToCategoryMapList[temp] ) );
循环运行3次,因为find()
返回3项。
但是,如果我取消注释,循环只运行一次。我在这里犯了什么错吗?
createPromiseToUpdateStoreToCategoryMapObject
更新/保存storeToCategoryMapList[temp]
中可用的对象。
storeToCategoryMapQuery.find().then(function( storeToCategoryMapList) {
console.log("updateAllStoresOfRetailerCategoryMapObject");
var promiseToSaveStoreToCategoryMap = Parse.Promise.as();
console.log("Total Stores = " + storeToCategoryMapList.length);
var listOfPromises = [];
for ( var temp=0; temp<storeToCategoryMapList.length;temp++) {
console.log(" temp =" + temp)
listOfPromises.push( createPromiseToUpdateStoreToCategoryMapObject( storeToCategoryMapList[temp] ) );
}
return Parse.Promise.when(listOfPromises);
}).then(function(){
console.log("Successs in updateAllStoresOfRetailerCategoryMapObject ");
finalPromise.resolve();
},function(error){
console.log("updateAllStoresOfRetailerCategoryMapObject error======" + JSON.stringify(error));
finalPromise.resolve("problem");
});