[英]Rxjs. Map each object Observable<Foo[]> using http call
Let's say, I have an endpoint which return Foo[]
.假设,我有一个返回
Foo[]
的端点。 Here is simpliest Foo
class:这是最简单的
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: 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;
}
I know there is a lot of Rxjs operators
which I can propably use but there is too many of them and I don't know which should i use.我知道有很多
Rxjs operators
我可以适当地使用,但是它们太多了,我不知道应该使用哪个。 Any ideas?有任何想法吗?
It will be written like:它会写成:
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.