Can a Knockout observable be data bound to the value of a radio button?

后端 未结 3 695
心在旅途
心在旅途 2021-01-21 08:31

Is it possible to bind a Knockout observable property to a radio button using a value binding?

Here\'s what I\'m trying to do, but the value ends up being the string \"[

3条回答
  •  一生所求
    2021-01-21 08:56

    As documented here only Select nodes have the ability to bind an arbitrary JavaScript object to a value. Other inputs require a string value, which is why your value is returning "[Object object]".

    You can still do what you want but you will have to manually map a key and find the appropriate object yourself. Here is a fiddle that demonstrates:

    http://jsfiddle.net/jearles/JcPXy/

提交回复
热议问题