0

我对可观察对象的管道有疑问

假设我有以下代码:

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}` )
);

在这里,您可以尝试堆栈闪电战

4

1 回答 1

3

与所有 ReactiveX 一样,您有很多选择。也许最接近您现在所拥有的是使用withLatestFrom ...

const source = combineLatest(skip$, length$).pipe(
  map(([skip, length]) => (`skip: ${skip}, length: ${length}`)),
  withLatestFrom(schoolId$),
  map(([text, schoolId]) => `${text}, schoolId: ${schoolId}` )
);
于 2020-01-23T14:51:41.480 回答