如何让 distinctUntilChanged
处理这样的对象
myObs = Observable.from([{foo: 'bar'}, {foo: 'bar'}]);
myObs.distinctUntilChanged()
.subscribe(value => {
// I only want to receive {foo: 'bar'} once
});
最佳答案
您需要在 distinctUntilChanged
中传递一个返回 bool 值的函数,以确保对象相同。
例子
myObs. distinctUntilChanged((a, b) => a.foo === b.foo)
关于javascript - 在对象上使用 distinctUntilChanged,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47140196/