在订阅相同的 observable 时获取 observable 的先前值 [英] Get previous value of an observable in subscribe of same observable

查看:20
本文介绍了在订阅相同的 observable 时获取 observable 的先前值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在收到新值之前,是否有可能在淘汰赛中获得对该 observable 的订阅中的 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");

这篇关于在订阅相同的 observable 时获取 observable 的先前值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆