Get previous value of an observable in subscribe of same observable

前端 未结 5 1563
抹茶落季
抹茶落季 2020-12-07 15:22

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?

Example:

<         


        
5条回答
  •  南方客
    南方客 (楼主)
    2020-12-07 16:10

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

提交回复
热议问题