如何在angularjs中的$ q.all中使用for循环

时间:2016-02-02 20:08:14

标签: angularjs

我正在尝试重复循环,拨打电话并保留所有承诺。这是我的代码:

loadpages:function(id,pages){
 var msg =[];
 var finalList =[];
 $q.all([
    for(var i=1;i<=pages;i++)
        this.getPages(id,i).then(function(promise){
            msg[i]= promise.data;
        })
    }),
  ]).then(function() {
    for(var j=1;j<=pageNo;j++){
        finalList.push(msg[j]);
    }
  })

  getPages:function(id,pageNo){
 data.payload = {
                id: id,
                page: pageNo,               
            };
            var promise = $http.post( url,data); 
            return promise;
        },
}

当我在$ q.all中保持for循环时出现错误。如何获得所有名单,持有所有承诺并成为一名决赛选手?

1 个答案:

答案 0 :(得分:1)

循环在$ q之外,而不在里面 - 尝试:

Double[] colorED = new Double[75];
Double[,] ColorEd = new Double[10, 10];
for (int i2 = 0; i2 < (colorfeature3.Count()) / color_no; i2++)
  {
      int cj = 0;
      for (int i3 = 0; i3 < 10; i3++)
   {
ColorEd[ci,cj]= (Math.Abs(colorfeature3[i2 * color_no + i3].GetHue()- colorarray[i3].GetHue()) + Math.Abs(colorfeature3[i2 * color_no + i3].GetSaturation() - colorarray[i3].GetSaturation()) +Math.Abs (colorfeature3[i2 * color_no + i3].GetBrightness() - colorarray[i3].GetBrightness()));
   } 
  }