EasyUI combobox下拉多选框的实现

combobox实现下拉列表多选, 效果如下

一、先定义一个easyui-combobox

<td>
     目标人群:
</td>
<td>
     <input id="cmbAgeType" class="easyui-combobox" name="dept" />
</td>

二、在javascript中写入如下代码

   $('#cmbAgeType').combobox({
                url: 'AjaxHandler/RadioCommon.ashx?action=bindAgeType',//对应的ashx页面的数据源
                method: 'get',
                valueField: 'CID',//绑定字段ID
                textField: 'CNAME',绑定字段Name
                panelHeight: 'auto',//自适应
                multiple: true,
                formatter: function (row) {
                    var opts = $(this).combobox('options');
                    return '<input type="checkbox" class="combobox-checkbox" id="' + row[opts.valueField] + '">' + row[opts.textField]
                },

                onShowPanel: function () {
                    var opts = $(this).combobox('options');
                    var target = this;
                    var values = $(target).combobox('getValues');
                    $.map(values, function (value) {
                        var el = opts.finder.getEl(target, value);
                        el.find('input.combobox-checkbox')._propAttr('checked', true);
                    })
                },
                onLoadSuccess: function () {
                    var opts = $(this).combobox('options');
                    var target = this;
                    var values = $(target).combobox('getValues');
                    $.map(values, function (value) {
                        var el = opts.finder.getEl(target, value);
                        el.find('input.combobox-checkbox')._propAttr('checked', true);
                    })
                },
                onSelect: function (row) {
                    var opts = $(this).combobox('options');
                    var el = opts.finder.getEl(this, row[opts.valueField]);
                    el.find('input.combobox-checkbox')._propAttr('checked', true);
                },
                onUnselect: function (row) {
                    var opts = $(this).combobox('options');
                    var el = opts.finder.getEl(this, row[opts.valueField]);
                    el.find('input.combobox-checkbox')._propAttr('checked', false);
                }
            });

三、后台传到前台的Json格式

[{"CID":1000,"CNAME":"10岁以上","CSEX":0,"CAGE":0,"CEDUCATION":0,"CINCOMING":0,"CMARRY":0,"CJOB":0,"CDECIDER":0,"CBACKUP1":0,"CBACKUP2":0,"CBACKUP3":0,"CARG1":"","CARG2":"","CARG3":"","CVALID":0,"CTX3":""},{"CID":1,"CNAME":"","CSEX":1,"CAGE":0,"CEDUCATION":0,"CINCOMING":0,"CMARRY":0,"CJOB":0,"CDECIDER":0,"CBACKUP1":0,"CBACKUP2":0,"CBACKUP3":0,"CARG1":"","CARG2":"","CARG3":"","CVALID":1,"CTX3":"1"},{"CID":2,"CNAME":"","CSEX":2,"CAGE":0,"CEDUCATION":0,"CINCOMING":0,"CMARRY":0,"CJOB":0,"CDECIDER":0,"CBACKUP1":0,"CBACKUP2":0,"CBACKUP3":0,"CARG1":"","CARG2":"","CARG3":"","CVALID":1,"CTX3":"2"},{"CID":1001,"CNAME":"10-19岁","CSEX":0,"CAGE":1,"CEDUCATION":0,"CINCOMING":0,"CMARRY":0,"CJOB":0,"CDECIDER":0,"CBACKUP1":0,"CBACKUP2":0,"CBACKUP3":0,"CARG1":"","CARG2":"10","CARG3":"19","CVALID":1,"CTX3":"1"},{"CID":1002,"CNAME":"20-29岁","CSEX":0,"CAGE":2,"CEDUCATION":0,"CINCOMING":0,"CMARRY":0,"CJOB":0,"CDECIDER":0,"CBACKUP1":0,"CBACKUP2":0,"CBACKUP3":0,"CARG1":"","CARG2":"20","CARG3":"29","CVALID":1,"CTX3":"2"},{"CID":1003,"CNAME":"30-39岁","CSEX":0,"CAGE":3,"CEDUCATION":0,"CINCOMING":0,"CMARRY":0,"CJOB":0,"CDECIDER":0,"CBACKUP1":0,"CBACKUP2":0,"CBACKUP3":0,"CARG1":"","CARG2":"30","CARG3":"39","CVALID":1,"CTX3":"3"},{"CID":1004,"CNAME":"40-49岁","CSEX":0,"CAGE":4,"CEDUCATION":0,"CINCOMING":0,"CMARRY":0,"CJOB":0,"CDECIDER":0,"CBACKUP1":0,"CBACKUP2":0,"CBACKUP3":0,"CARG1":"","CARG2":"40","CARG3":"49","CVALID":1,"CTX3":"4"},{"CID":1005,"CNAME":"50岁以上","CSEX":0,"CAGE":5,"CEDUCATION":0,"CINCOMING":0,"CMARRY":0,"CJOB":0,"CDECIDER":0,"CBACKUP1":0,"CBACKUP2":0,"CBACKUP3":0,"CARG1":"","CARG2":"50","CARG3":"200","CVALID":1,"CTX3":"5"}]

 

posted @ 2016-08-26 15:12  高空燕子飞过  阅读(17778)  评论(1编辑  收藏  举报