站内搜索:
首页 >> 前端 >> 内容
关于easyuicombobox下拉框实现多选框的实现教程

时间:2018/1/23 13:37:13

关于easyuicombobox下拉框实现多选框的实现教程

function initCombobox(id,url){  
            var value = "";  
            //加载下拉框复选框  
            $('#'+id).combobox({  
                url:url, //后台获取下拉框数据的url  
                method:'post',  
                panelHeight:200,//设置为固定高度,combobox出现竖直滚动条  
                valueField:'Id',  
                textField:'value',  
                multiple:true,  
                formatter: function (row) { //formatter方法就是实现了在每个下拉选项前面增加checkbox框的方法  
                    var opts = $(this).combobox('options');  
                    return '<input type="checkbox" class="combobox-checkbox">' + row[opts.textField]  
                },  
                onLoadSuccess: function () {  //下拉框数据加载成功调用  
                    var opts = $(this).combobox('options');  
                    var target = this;  
                    var values = $(target).combobox('getValues');//获取选中的值的values  
                    $.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');  
                    //获取选中的值的values  
                    $("#"+id).val($(this).combobox('getValues'));  
                     
                   //设置选中值所对应的复选框为选中状态  
                    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');  
                    //获取选中的值的values  
                    $("#"+id).val($(this).combobox('getValues'));  
                    
                    var el = opts.finder.getEl(this, row[opts.valueField]);  
                    el.find('input.combobox-checkbox')._propAttr('checked', false);  
                }  
            });  
        }  
<script>


$(function(){
initCombobox('IdList','urldata');
});
</script>
     <input id="IdList" name="IdList"  style="width:100%"  class="easyui-combobox" >  

 json.IdList  = (","+$('#IdList').combobox('getValues')+",")   

  • 上一篇:什么是质数?如何求的返回100以内的质数?
  • 下一篇:vue-router路由切换组件重用遇到的问题及解决方法
  • 返回顶部