合并/合并到数组

时间:2018-12-16 23:06:39

标签: rxjs6

我现在有这个:

import {concat, Observable, ReplaySubject, pipe, merge} from 'rxjs';
import {takeUntil, takeWhile, toArray} from 'rxjs/operators';


const rs1 = new ReplaySubject(1);  
const rs2 = new ReplaySubject(1);
const rs3 = new ReplaySubject(1);

rs1.next(1);
rs2.next(2);
rs3.next(2);

merge(rs1,rs2,rs3).pipe(toArray()).subscribe(v => {
  console.log({v});
});

现在它什么都没有记录,但是我希望得到记录:

{v: [1,2,3]}

如何合并/合并到数组?

1 个答案:

答案 0 :(得分:2)

然后,您应该使用zip而不是merge

import {ReplaySubject, zip} from 'rxjs';


const rs1 = new ReplaySubject(1);  
const rs2 = new ReplaySubject(1);
const rs3 = new ReplaySubject(1);

rs1.next(1);
rs2.next(2);
rs3.next(2);

zip(rs1,rs2,rs3).subscribe(v => {
  console.log({v});
});