[英]How to unwrap an observable inside a map in rxjs?
如何在以下地圖中解開 observable (this.fireStore.getExtras(v["extrasId"]))
?
this.authService
.getUser()
.pipe(
flatMap((val) => this.fireStore.getItems(val.uid)),
map((val) =>
val.map((v) => ({ // this is regular array.map
...v,
extras: {
...v["extras"],
url: (this.fireStore.getExtras(v["extrasId"])).url // this is an observable. I want it to be unwrapped inside here itself,
},
}))
)
)
這是要展開的內部 observable (this.fireStore.getExtras(v["extrasId"]))
。 我試過flatMap
但它正在返回函數本身..., url: flatmap() => ...
未經測試
this.authService.getUser().pipe(
flatMap(val => this.fireStore.getItems(val.uid)),
switchMap(val => {
return forkJoin(val.map(v => this.fireStore.getExtras(v.extrasId).pipe(map(x => ({...v, extras: {...v.extras, url: x.url}}))))),
}),
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.