I using knockout for mapping JSON obejct to user control, I have a list of single checkboxes, They look like
<input type="checkbox" data-bind="checked: IsEnabled1" />
I Have JsonObject
var viewModel = {
IsEnabled1 :ko.observable(true),
IsEnabled2 :ko.observable(true),
IsEnabled3 :ko.observable(false)
};
...
ko.applyBindings(viewModel);
And I want to add global check box that will be check/uncheck all other, I made this changes on JavaScript side but global check box update UI part but they data from separate check boxes doesn't mapping to JSON object .
Global checkbox
$("#GeneralTable thead tr th:first input:checkbox").click(function () {
var checkedStatus = this.checked;
$("#GeneralTable tbody tr td:first-child input:checkbox").each(function () {
this.checked = checkedStatus;
});
});
after this code my JSON object contain data that not related to UI.
How to update all JSON after change check boxes from JS side ?
Please check the example: http://jsfiddle.net/MenukaIshan/5gaLjh2c/
I think it is exactly what you need. All items have IsChecked
observable property. ViewModel contains computed observable (readable and writeable) to check or uncheck all items.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With