繁体   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