2017-08-27 37 views
0
Observable.forkJoin(
    this.ids.map(
    i => this.http.get('api_url' + i) //return a json for each url 
     .map(res=> res.json()) 
)).subscribe(res=> this.data = res.data) 

它提示[ts] Property 'data' does not exist on type 'any[]'.那麼我怎樣才能從forkjoin響應中獲得json?從Observable.forkjoin獲取json

回答

0

ForkJoin會返回響應數組,您將需要遍歷數組來獲取每個請求的數據。

this.data = []; 
Observable.forkJoin(this.ids.map(i => this.http.get('api_url' + i) //return a json for each url .map(res=> res.json()))).subscribe(aRes=> { 
    aRes.forEach((res) => this.data.push(res.data)); 
});