Knockout force select update binding

≡放荡痞女 提交于 2020-01-17 11:17:12

问题


I have an address form for multiple addresses.

http://jsfiddle.net/VAs5r/6/

When the form is loaded, the addresses object has a value Active:false that is bind to the enable property to all the input fields in order to block any entry. Then a button named "new address" change the Active property to true in order to enable all the inputs and let the user to enter information.

Is working but the problem is that is not refreshing the fields until you change the select option and then return again to the current address type.

Is there any work around to this?

Thanks.


回答1:


Here is your fiddle, updated and working.

The problem you were having is that this is not a valid way to set observable values:

self.selectedAddress().active=true;

In knockout, observables are functions, and are set by passing new values to them as parameters, like this:

self.selectedAddress().active(true);

When you set observables the way you were doing it, their "observability" is overwritten, and they become standard objects. When this happens, the UI is not notified of their updates.



来源:https://stackoverflow.com/questions/11365664/knockout-force-select-update-binding

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!