剔除选中/取消选中所有组合框 [英] knockout check/uncheck all combo box

查看:75
本文介绍了剔除选中/取消选中所有组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用敲除功能将JSON对象映射到用户控件,我有一个复选框列表, 它们看起来像

 <input type="checkbox" data-bind="checked: IsEnabled1" />

我有JsonObject

 var viewModel = {
            IsEnabled1 :ko.observable(true),            
            IsEnabled2 :ko.observable(true),
            IsEnabled3 :ko.observable(false)
        };
  ...
  ko.applyBindings(viewModel);

我想添加将被选中/取消选中所有其他复选框的全局复选框,我在JavaScript端进行了此更改,但是全局复选框更新了UI部分,但它们来自单独复选框的数据未映射到JSON对象. /p>

全局复选框

  $("#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不相关的数据.

如何从JS端更改复选框后更新所有JSON?

解决方案

请检查示例: http://jsfiddle.net/MenukaIshan/5gaLjh2c/

我认为这正是您所需要的.所有项目均具有IsChecked可观察的属性. ViewModel包含计算得出的可观察(可读和可写)形式,用于检查或取消选中所有项目.

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.

这篇关于剔除选中/取消选中所有组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆