Angular 2 Observable.forkJoin with for 循环

Man*_*anu 4 rest typescript angular

这就是我现在的工作方式:

getTwoObjectById(url1: string, id1: string, url2: string, id2): any{
  return Observable.forkJoin(
    this.http.get(url1 + `/${id1}`, this.jsonWebToken()).map(res => 
      res.json()),
    this.http.get(url2 + `/${id2}`, this.jsonWebToken()).map(res => 
      res.json())
  );
}
Run Code Online (Sandbox Code Playgroud)

我想用 id1, url1, id2, url2, id3, url3 ...

我正在尝试编写一个函数,该函数应将 ID 数组和 URL 数组作为参数。使用Observable.forkJoinfor 循环应该执行每个请求 getById 到 Array 中的 Backend-URL。我的问题是 for 循环

getObjectsById(ids: Array<string>, urls: Array<string>): Observable<any>{
  return Observable.forkJoin(

  for(let i = 0; i++; i<ids.length) {

     this.http.get(urls[i] + `/${ids[i]}`, this.jsonWebToken()).map(res => res.json());

  }

 )
}  
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

Rah*_*ngh 7

尝试使用这个

inputObject = [1, 2, 3, 4];


getObjectsById() {
    let observableBatch = [];

    this.inputObject.forEach((key) => {
      observableBatch.push(this.http.get(url+key).map((res) => res.json()));
    });

    return Observable.forkJoin(observableBatch);
  }
Run Code Online (Sandbox Code Playgroud)