オブジェクトに2つのidがある場合、最初のオブジェクトが取得された後に2つの呼び出しを行う観測可能なストリームがあります。 idの1つはオプションであり、そこに存在していなくてもよい。 siteIdはオプションのIDです。見つかった場合は、getTeamと同じように呼び出しを行う必要があります。条件付きコールを作成するにはどうすればよいですか?私がこれを動作させることができた唯一の方法は、subscribeメソッドの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