Checkboxes are not updating when I foreach loop and bind a boolean to a checkbox.
function ViewModel() {
var self = this;
self.test = ko.observableArray([ false, false, false ]);
return self;
}
ko.applyBindings(new ViewModel());
<div data-bind="text: ko.toJSON(test)"></div>
<div data-bind="foreach: $root.test">
<input type="checkbox" data-bind="checked: $data" />
</div>
You can view the issue on jsfiddle:
http://jsfiddle.net/KVWet/1/
http://knockoutjs.com/documentation/checked-binding.html
Because if an item is checked its value is added to an array. If it isn’t checked it takes it away. I think for this to work you will need keys added to the array so it can match with the checkbox it belongs to. An array of booleans won’t help ko map it to its respective checkbox.