项目中经常会遇到下拉选择框!但是当选项过多时,不允许开启编辑检索,客户选择必然很麻烦!但是开启可编辑后【editable:true,】,总会遇到客户非法输入,或者组件获取不到选项ID,导致提交异常!处理结果很简单!安排一下!
例如下面是一个选择器
<input class="easyui-combobox" name="brand" id="brand" data-options=" url: '...', method: 'get', required:true, missingMessage:'必填项', editable:true, valueField:'id', textField:'bName', onHidePanel: function(val) {//下拉框消失时触发 var thisName = $(this).combobox('getText');//获取输入内容 var thisId;//用来存储ID var itemList = $(this).combobox('getData');//获取组件数据 var if_found = false;//用来标记该内容是否存在 $.each(itemList, function(index, item) {//判断输入内容是否存在 if (item.bName == thisName) { if_found = true; thisId = item.id; return false;//直接return;是 continue, return false;是break } }); if(if_found){ $(this).combobox('clear');//一定要先清除内容,否则无法触发onSelect事件 $(this).combobox('select', thisId);//做onSelect处理,触发联动操作 }else{ alert('该品牌【'+thisName+'】不存在,请核实!'); } }, onSelect:function(rec){ $('#xxx').combobox('reload',xxxx);//事件中可以做其他组件的联动处理 } ">
这样再配上相应的逻辑处理,就能限制用户的非法输入了!同时也可以触发相关的联合操作!