Build Knockout Model And View Dynamically, Radio Buttons Not Being Set
I am in the process of making one of my previous questions fully dynamic in that the model is built from server data, and the view loops through the viewmodel via the knockout ko f
Solution 1:
You have two problems:
You are not correctly binding your radio button's names:
name="$parent.name"
is not a knockout binding expression and it just assigns the string"$parent.name"
to all of your radio buttons. What you need is to use theattr
binding:<input type="radio" data-bind="checkedValue: $data, checked: $parent.selection, attr: { name: $parent.name }" />
The initial selection is not working because you are using the
checkedValue: $data
option this means that yourchecked
should contain the whole object and not just one property (sku
) so you need to change yourcomputedOptions.subscribe
to:computedOptions.subscribe(function () { var section = this; section.selection(section.options()[0]); },section);
Demo JSFiddle.
Post a Comment for "Build Knockout Model And View Dynamically, Radio Buttons Not Being Set"