我对可观测对象的管道有疑问
假设我有以下代码:
const skip$ = of(4);
const length$ = of(24);
const schoolId$ = of(1);
const source = combineLatest(skip$, length$, schoolId$).pipe(
map(([skip, length]) => `skip: ${skip}, length: ${length}`),
map(text => text ) // I need now schoolId, how can i get
);
在第二张地图中,我需要schoolId。不这样做,如何获取schoolId:
const source = combineLatest(skip$, length$, schoolId$).pipe(
map(([skip, length, schoolId]) => ({text: `skip: ${skip}, length: ${length}`, schoolId})),
map(text => `${text.text}, schoolId: ${text.schoolId}` )
);
您有stackblitz可以尝试
答案 0 :(得分:3)
与ReactiveX一样,您还有很多选择。也许最接近您现在使用的是使用withLatestFrom ...
const source = combineLatest(skip$, length$).pipe(
map(([skip, length]) => (`skip: ${skip}, length: ${length}`)),
withLatestFrom(schoolId$),
map(([text, schoolId]) => `${text}, schoolId: ${schoolId}` )
);