我需要知道解决这个问题的好方法。
我正在调用与 switchMaps 连接的三个服务,但我需要最后一个服务的第一个服务变量。这样做的最佳做法是什么?
例子:
this.session.account.get()
.switchMap(account => this.employerApi.get(account.accountId))
.switchMap(employer => this.addressApi.get(employer.addressId))
.filter(address => address.numer % 2)
.subscribe(address => console.log(¿¿¿¿¿account.name?????, address.name));
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助
最简单的方法是在您进行时汇总值:
this.session.account.get()
.switchMap(account =>
this.employerApi.get(account.accountId).map(employer => ({employer, account}))
.switchMap(data =>
this.addressApi.get(employer.addressId).map(address => ({...data, address}))
.filter(data => data.address.number % 2)
.subscribe(...)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1150 次 |
| 最近记录: |