【发布时间】:2023-03-28 11:00:01
【问题描述】:
this.httpService
.getCustomer(id)
.pipe(
switchMap((customerObj) => this.httpService.getCustomerAccount(customerObj.account_id)),
switchMap((accountObj) =>
this.httpService.getAccountHoliday(accountObj.holiday_id),
),
)
.subscribe((holidays: Holiday[]) => {
for (const holiday of holidays) {
this.httpService.getDestination(holiday.dest_id).subscribe((destination) => {
if (holiday.identifier === destination.name) {
console.log(holiday);
}
});
}
});
我想做这样的事情
this.httpService
.getCustomer(id)
.pipe(
switchMap((customerObj) => this.httpService.getCustomerAccount(customerObj.account_id)),
switchMap((accountObj) =>
this.httpService.getAccountHoliday(accountObj.holiday_id),
),
filter(holiday => this.httpService.getDestination(holiday.dest_id).name === holiday.identifier)
)
.subscribe((holiday: Holiday[]) => {
for (const holiday of holidays) {
console.log(holiday);
}
});
也就是说,将 for 循环的逻辑与过度服务合并,即我需要在订阅之前过滤掉假期。我该怎么做?
【问题讨论】:
-
您介意解释清楚用例吗?
标签: angular rxjs rxjs-observables