0
我有以下代碼:與rxjs處理可觀測量邏輯
Observable.combineLatest(
this.data.getPersonalData(myfilter),
this.peopleService.selectedPerson,
).subscribe(([data, person]) => {
this._data = data;
if (this._data.length) {
this.infoService.getInfo(
person.id
)
.subscribe(res => {
this.handleInfo(res);
});
}
});
Observable.combineLatest(
this.data.getPersonalData(myfilter),
this.sectionService.selectedSection
).subscribe(([data, section]) => {
this.filterbySection(s);
});
我會盡量解釋的場景:
首先,我們得通過myfilter
給所有可用的personaldata。 Okey,所以現在,給定一個selectedPerson
我們獲得一個人的所有信息,並且handleInfo
將這個信息關聯到data
中的一組對象。但事情是,當它結束時,我想要filterbySection
當我有一個selectedSection
。
我知道我可以把this.sectionService.selectedSection
第一combineLatest
,但每次用戶更改部分,它將運行infoService
要去數據庫,並把所有的信息,我不需要這種行爲。當我選擇一個人時,我需要運行getInfo
,處理此信息將其映射到_data
,然後按部分過濾所有「info + data」,每次用戶單擊一個新節。