我有一系列的观察者,想要传递给他们Rx.Observable.zip
.我试过了,根本没有订阅.
代码片段(仅举例):
const sourceOne = Rx.Observable.of('Hello'); const sourceTwo = Rx.Observable.of('World!'); const sourceThree = Rx.Observable.of('Goodbye'); const sourceFour = Rx.Observable.of('World!'); const arr$ = [sourceOne, sourceTwo, sourceThree, sourceFour]; const zip$ = (a$) => Rx.Observable.zip(a$); const subscribe = zip$(arr$).subscribe(val => console.log(val));
有没有办法将数组传递给Rx.Observable.zip
?
运算符zip
只接受解压缩的数组.
Rx.Observable.zip(sourceOne, sourceTwo, sourceThree, ...);
如果您正在使用ES6,您还可以使用解构分配...
:
const zip$ = (a$) => Rx.Observable.zip(...arr$);
观看现场演示:https://jsbin.com/tinaxeq/1/edit?js,console