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”,每次用户单击一个新节。