我如何从不断变化的来源进行订阅?
$1,i
答案 0 :(得分:1)
您应该封装数组,使其与可以观察到的主题紧密结合:
myArray = [1,2,3,4,5];
const observable = new Rx.Subject();
observable.next(myArray);
const subscribe = observable.subscribe(val => console.log(val));
myArray.push(10);
observable.next(myArray); // after each push reemit the array
myArray.push(11);
observable.next(myArray);