动态绑定的元素,applyBindingsToNode不响应更改 [英] Dynamically bound elements with applyBindingsToNode not responding to changes
本文介绍了动态绑定的元素,applyBindingsToNode不响应更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在此示例中,我具有动态绑定的输入和div相同的属性. 但是在更改输入中的文本时,更改不会反映在div元素中.
In this example I have a dynamically bound input and div to the same property. But on altering text in input, changes are not reflected in the div element.
http://jsfiddle.net/rpuri/Bcps5/
ko.applyBindingsToNode(document.getElementById('input-health'), {
value: vm.status(),
valueUpdate: 'afterkeydown'
});
声明性绑定对我来说不是一个选择,因为我需要绑定到局部视图(ASP.NET MVC)中的共享元素.
Declarative binding is not an option for me because I need to bind to shared elements in partial views (ASP.NET MVC).
谢谢
推荐答案
您将绑定到可观察对象的值,而不是可观察对象本身.
You are binding to the value of the observable instead of the observable itself.
尝试:
ko.applyBindingsToNode(document.getElementById('health'), {
text: vm.status, // <- not invoking status, binding to the observable itself.
valueUpdate: 'keydown'
});
ko.applyBindingsToNode(document.getElementById('input-health'), {
value: vm.status,
valueUpdate: 'keydown'
});
这篇关于动态绑定的元素,applyBindingsToNode不响应更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文