敲除强制选择更新绑定 [英] Knockout force select update binding

查看:94
本文介绍了敲除强制选择更新绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含多个地址的地址表格.

I have an address form for multiple addresses.

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

在加载表单时,地址对象的值Active:false绑定到所有输入字段的enable属性以阻止任何输入.然后,一个名为新地址"的按钮将Active属性更改为true,以启用所有输入并允许用户输入信息.

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?

谢谢.

推荐答案

这里是您的小提琴,更新并正常工作.

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

当您以可观察的方式进行设置时,它们的可观察性"将被覆盖,并且它们成为标准对象.发生这种情况时,UI不会收到有关其更新的通知.

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.

这篇关于敲除强制选择更新绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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