剔除是否有可能在获取新观察值之前获取该观察值的预订中的当前值?

例:

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值进行订阅:

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");

07-26 01:08