我正在使用 Rx.js 将 AJAX 调用的结果流式传输到多个单元。
但是当有多个观察者订阅 MapObserver 时,我遇到了问题。当第一个订阅者总是获得正确的数据,但其余的数据将变得不确定时。
this.observable = new Rx.Subject();
observeMap = this.observable
.map(createMarker.bind(this));
var s1 = observeMap.subscribe(console.log.bind(console, 1));
var s2 = observeMap.subscribe(console.log.bind(console, 2));
请指教,谢谢!
最佳答案
我刚刚找到了我的问题的解决方案,为了在少数订阅者之间共享可观察的内容,您可以使用 share方法。
this.observable = new Rx.Subject();
observeMap = this.observable
.map(createMarker.bind(this))
.share();
var s1 = observeMap.subscribe(console.log.bind(console, 1));
var s2 = observeMap.subscribe(console.log.bind(console, 2));
关于javascript - Rx.js,Subscribe 被调用时未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29468491/