Jquery中文网 www.jquerycn.cn
Jquery中文网 >  jQuery  >  jquery 教程  >  正文 jquery easyui combobox模糊过滤(示例代码)

jquery easyui combobox模糊过滤(示例代码)

发布时间:2014-05-20   编辑:www.jquerycn.cn
这篇文章主要介绍了jquery easyui combobox模糊过滤(示例代码)。需要的朋友可以过来参考下,希望对大家有所帮助

修改jquery easyui combobox模糊过滤

复制代码 代码如下:

filter:function(q,row){
var opts=$(this).combobox("options");

//return row[opts.textField].indexOf(q)==0;//

return row[opts.textField].indexOf(q)>-1;//将从头位置匹配改为任意匹配
},formatter:function(row){
var opts=$(this).combobox("options");
return row[opts.textField];
},loader:function(_7c9,_7ca,_7cb){
var opts=$(this).combobox("options");
if(!opts.url){
return false;
}

修改easyui combobox扩展可以默认选择第一行

easyui的combobox扩展默认选择第一行,网上有疯狂秀才的那个被转载了无数次的代码,但是那个只是针对easyui1.2.6的,试了一下在1.3.2下不行的,自己重新写了一个扩展方法如下:

复制代码 代码如下:

$.extend($.fn.combobox.methods, {
    selectedIndex: function (jq, index) {
        if (!index) {
            index = 0;
        }
        $(jq).combobox({
            onLoadSuccess: function () {
                var opt = $(jq).combobox('options');
                var data = $(jq).combobox('getData');

                for (var i = 0; i < data.length; i++) {
                    if (i == index) {
                        $(jq).combobox('setValue', eval('data[index].' + opt.valueField));
                        break;
                    }
                }
            }
        });
    }
});

调用方法实例如下:
复制代码 代码如下:

<script type="text/javascript">
var currenturl = "om_taking.aspx";
        $(function () {
            $('#dept').combobox({
                url: currenturl + "?act=loadDept",
                valueField: 'DEPARTMENT_ID',
                textField: 'DEPARTMENT_NAME'
            }).combobox('selectedIndex', 0);
        });
</script>

您可能感兴趣的文章:
jquery easyui combobox模糊过滤(示例代码)
jquery easyui中combobox设为只读
jQuery EasyUI 表单 – 过滤下拉数据网格(ComboGrid)
jquery easyui通过class方式设置dialog
jquery easyui自定义下拉框列表
Jquery通过Ajax方式来提交Form表单的具体实现
jQuery EasyUI 教程
jQuery EasyUI 简介
jquery easyui中combox数据获取实例
jquery easyUI创建分组属性编辑器

关键词: jquery  easyui   
[关闭]