订阅相同的可观察对象,获取该可观察对象的先前值 [英] Get previous value of an observable in subscribe of same observable
本文介绍了订阅相同的可观察对象,获取该可观察对象的先前值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在剔除中,是否有可能在订阅中获得可观察值的当前值,然后再接收新值?
Is it possible in knockout to get the current value of an observable within a subscription to that observable, before it receives the new value?
示例:
this.myObservable = ko.observable();
this.myObservable.subscribe(function(newValue){
//I'd like to get the previous value of 'myObservable' here before it's set to newValue
});
推荐答案
有一种方法可以像这样对before值进行订阅:
There is a way to do a subscription to the before value like this:
this.myObservable = ko.observable();
this.myObservable.subscribe(function(previousValue){
//I'd like to get the previous value of 'myObservable' here before it's set to newValue
}, this, "beforeChange");
这篇关于订阅相同的可观察对象,获取该可观察对象的先前值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文