通过数组响应循环获取请求

时间:2017-07-19 15:37:08

标签: angularjs typescript ionic-framework

我想将来自getLocation的信息存储在位置数组中,并将值转换为float。但我不知道如何循环存储值

this.peopleservice.getLocation(ID)
   .subscribe(data =>{this.latcoor = data[x].lat,
    this.lngcoor=data[x].lng

   this.lat= parseFloat(this.latcoor);
   this.lng= parseFloat(this.lngcoor);

  this.location= [
            {latitude:this.lat, longitude:this.lng},
        ];
  });}

1 个答案:

答案 0 :(得分:1)

使用for循环如下:

this.peopleservice.getLocation(ID)
   .subscribe(data => {
    this.location = [];
    for (let item of data) {
      this.location.push({latitude: parseFloat(item.lat), longitude: parseFloat(item.lng)});
    }
  });