淘汰赛选中/取消选中所有组合框 [英] knockout check/uncheck all combo box
问题描述
我使用淘汰赛将 JSON 对象映射到用户控件,我有一个单复选框列表,他们看起来像
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" />
我有 JsonObject
I Have JsonObject
var viewModel = {
IsEnabled1 :ko.observable(true),
IsEnabled2 :ko.observable(true),
IsEnabled3 :ko.observable(false)
};
...
ko.applyBindings(viewModel);
并且我想添加将选中/取消选中所有其他复选框的全局复选框,我在 JavaScript 端进行了此更改,但全局复选框更新了 UI 部分,但它们来自单独复选框的数据未映射到 JSON 对象.
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 .
全局复选框
$("#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;
});
});
在此代码之后,我的 JSON 对象包含与 UI 无关的数据.
after this code my JSON object contain data that not related to UI.
从 JS 端更改复选框后如何更新所有 JSON?
How to update all JSON after change check boxes from JS side ?
推荐答案
请查看示例:http://jsfiddle.net/MenukaIshan/5gaLjh2c/
我认为这正是您所需要的.所有项目都具有 IsChecked
可观察属性.ViewModel 包含计算的 observable(可读和可写)以检查或取消选中所有项目.
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.
这篇关于淘汰赛选中/取消选中所有组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!