![](/img/trans.png)
[英]Using map<int, Foo> instead of vector<Foo> to avoid pointer invalidation
[英]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.