Radiobutton Checked值返回“on”而不是真的 [英] Radiobutton Checked value return "on" instead of true

查看:176
本文介绍了Radiobutton Checked值返回“on”而不是真的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的小提琴 http://jsfiddle.net/9y8nm14m/ [ ^ ]



我已经使用ko.mapping插件加载了我的viewmodel负载工作正常。当我尝试发布内容时,除了radiobutton的值之外,所有值都正常工作,检查的值返回on[String]而不是true [bool]。我错过了什么或做了什么我需要为此编写计算。



我在敲击foreach中加载radiobutton。

解决方案

< blockquote>非常有趣。这不起作用。



如果你看到官方文档 - 已检查绑定 [ ^ ],它说...

引用:

对于单选按钮,KO将设置要检查的元素并且仅当参数值等于单选按钮节点的value属性或checkedValue参数指定的值时。在前面的示例中,仅当视图模型的spamFlavor属性等于杏仁时才检查值为杏仁的单选按钮。



当用户更改时选择了哪个单选按钮,KO会将您的模型属性设置为等于所选单选按钮的值。在前面的示例中,单击值为cherry的单选按钮会将viewModel.spamFlavor设置为cherry。



请参阅更新的演示 - [Demo] Knockout RadioButton Binding [ ^ ]。


Here is my fiddle http://jsfiddle.net/9y8nm14m/[^]

I have loaded my viewmodel with the ko.mapping plugin and the load is working fine.When I try to post the content all the values are working fin except the value for the radiobutton the checked value is returning "on"[String] instead of true[bool].Am i missing something or Do i need to write compute for this.

I am loading the radiobutton with in the knockout foreach .

解决方案

Very interesting. This does not work this way.

If you see the official documentation - The "checked" binding[^], it says...

Quote:

For radio buttons, KO will set the element to be checked if and only if the parameter value equals the radio button node’s value attribute or the value specified by the checkedValue parameter. In the previous example, the radio button with value="almond" was checked only when the view model’s spamFlavor property was equal to "almond".

When the user changes which radio button is selected, KO will set your model property to equal the value of the selected radio button. In the preceding example, clicking on the radio button with value="cherry" would set viewModel.spamFlavor to be "cherry".


See the updated demo - [Demo] Knockout RadioButton Binding[^].


这篇关于Radiobutton Checked值返回“on”而不是真的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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