确定KnockoutJS中的属性更改事件? [英] Identify the attribute change event in KnockoutJS?

查看:96
本文介绍了确定KnockoutJS中的属性更改事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在KnockoutJS中识别属性更改事件?
我在jQuery中找到了解决方案:
关于DOM属性更改的触发事件
针对DOM属性更改触发事件

Is there any way to Identify the attribute change event in KnockoutJS?? I found solutions in jQuery: firing event on DOM attribute change firing event on DOM attribute change

但如果我能用KO做的话会很好。

But It would be good If I can do it with KO.

谢谢。

推荐答案

如果属性更改绑定到视图模型中的属性,那么您只需订阅该属性即可获得更改通知。

If the attribute change is bound to a property in your view model, then you can simply subscribe to that property to get notified of changes.

myViewModel.myProperty.subscribe(function(newValue) {
    alert("This property changed!!");
});

这篇关于确定KnockoutJS中的属性更改事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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