簡體   English   中英

Rxjs。 Map 每個 object 可觀察<foo[]>使用 http 調用</foo[]>

[英]Rxjs. Map each object Observable<Foo[]> using http call

假設,我有一個返回Foo[]的端點。 這是最簡單的Foo class:

class Foo{
booId: number;
someProperty: string;
}

And what I want to do, is call another Http request for each Foo object to fetch Boo object with booId , then merge those two objects into one and return object which looks like that:

class FooWithBoo{
boo: Boo;
someProperty: string;
}

我知道有很多Rxjs operators我可以適當地使用,但是它們太多了,我不知道應該使用哪個。 有任何想法嗎?

它會寫成:

http.get(/*url to get Foo[]*/)
 .pipe(
   mergeMap(fooArray => from(fooArray)), //flatMap the returned array
   concatMap(foo => http.get(/*url to get Boo*/ + foo.booId))
 )
 .subscribe()
 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM