【发布时间】:2018-12-14 13:36:38
【问题描述】:
我已经定义了一个behaviorSubject:
measurementSearchChange$ = new BehaviorSubject('');
this.measurementSearchChange$
.asObservable()
.pipe(debounceTime(500))
.pipe(
switchMap((keyword: string) =>
this.warningService.getInfluxdbQuery(
this.selectedMonitorOption,
'measurement',
{ search_name: keyword }
)
)
)
.subscribe((data: any) => {
this.measurementOptions = data;
this.isLoading = false;
});
当一些动作时,会这样做:
this.measurementSearchChange$.next(keyword);
它现在运行良好,但我想添加一个 switchMap 并压缩它们,以便我可以订阅两个不同的数据,例如:
this.measurementSearchChange$
.asObservable()
.pipe(debounceTime(500))
.pipe(
switchMap((keyword: string) =>
this.warningService.getInfluxdbQuery(
this.selectedMonitorOption,
'measurement',
{ search_name: keyword }
)
// another
this.warningService.getInfluxdbQuery2(
this.selectedMonitorOption,
'measurement2',
{ search_name: keyword }
)
)
)
.subscribe((data1: any, data2: any) => {
this.measurementOptions = data;
this.isLoading = false;
});
那么怎么做呢?任何帮助表示感谢
【问题讨论】: