Passing variable to promise in a loop

后端 未结 5 1178
一生所求
一生所求 2021-01-30 05:40

I have a promise in a loop, and I don\'t know how to pass some scope variables into the promise handler.

for(var i in superarray){
    MyService.get(superarray[i         


        
5条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-30 05:53

    You can simplify the code a bit by using the built-in Array.prototype.forEach:

    superarray.forEach(function (item, index) {
        MyService.get(item.externalID).then(function(r) {
            console.debug(index);
        });
    });
    

提交回复
热议问题