可觀察到流我有一個觀察的數據流,使兩個呼叫最初的對象是使用檢索經過兩次的ID在對象中找到。其中一個ID是可選的,可能會或可能不會。 siteId是可選的ID。如果發現我必須完全按照getTeam的要求撥打電話。我如何進行條件性調用?我能夠得到這個工作的唯一方法是通過檢查訂閱方法中的id並從那裏撥打電話。然而,代碼將嵌套訂閱,我想避免。與條件調用
private getZone() {
this.spinner.show();
this.zonesService.getZone(this.zoneId)
.map(response => {
this.zone = response['group'];
this.teamId = this.zone['TeamId'];
this.siteId = this.zone['SiteId'];
return this.zone;
})
.flatMap(() => this.teamsService.getTeam(this.teamId))
.map(response => {
if (response['team']) {
this.team = response['team'];
if (this.team['personal']) { this.team['name'] = 'Personal Team'; }
this.zone['teamName'] = this.team['name'];
}
return response;
})
.subscribe(
_data => {
if (this.zone['personal']) { this.zone['name'] = 'My Personal Zone'; }
if (this.siteId) {
this.sitesService.getSite(this.siteId)
.subscribe(
_data => {
this.site = _data['site'];
}
);
}
this.spinner.hide();
this.loading = false;
}
);
}
任何幫助將不勝感激。謝謝。
謝謝,那很好。 – Aaron