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 \"[
I needed this too. My solution was similar to John Earles except I used a computed
instead of subscribe
:
self.selectedVehicleGroup = ko.computed(function(){
return ko.utils.arrayFirst(self.availableGroups(), function (group) { return group.name() == self.selectedGroupOption(); });
});
http://jsfiddle.net/JcPXy/91/
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/
FYI for other readers coming to the accepted answer, KO v3 added the checkedValue binding which now makes this possible.