javascript - Knockout.js binding radio group does not work -
i feel stupid can't make work :)
i made simple fiddle prove i'm not missing in big project.
html:
<div> preferred flavor <div><input type="radio" name="flavorgroup" data-bind="checked: cherryon" /> cherry</div> <div><input type="radio" name="flavorgroup" data-bind="checked: almondon" /> almond</div> <div><input type="radio" name="flavorgroup" data-bind="checked: mgon" /> monosodium glutamate</div> </div> js:
var viewmodel = { cherryon: ko.observable(true); almondon: ko.observable(false); mgon: ko.observable(false); }; ko.applybindings(viewmodel); i expect see cherry selected on start..
from knockout's documentation (http://knockoutjs.com/documentation/checked-binding.html):
for radio buttons, ko set element checked if , if parameter value equals radio button node’s value attribute.
example: http://jsfiddle.net/btkmr/2/
<div> preferred flavor <div><input type="radio" name="flavorgroup" value="cherry" data-bind="checked: flavor" /> cherry</div> <div><input type="radio" name="flavorgroup" value="almond" data-bind="checked: flavor" /> almond</div> <div><input type="radio" name="flavorgroup" value="monosodium" data-bind="checked: flavor" /> monosodium glutamate</div> </div> var viewmodel = { flavor: ko.observable("cherry") }; ko.applybindings(viewmodel);
Comments
Post a Comment