您的位置:首页 > 产品设计 > UI/UE

easyUI combobox 文本框模糊搜索问题

2017-04-15 13:25 363 查看
easyUI combobox默认自带搜索,但是其搜索是默认从第一个字符开始匹配,没有实现模糊搜索。

解决方案:利用filter属性,对其进行重写,对照其官方解释,如图:



看到解释,确实是根据返回的搜索框关键字(q变量),对其进行匹配,且从第一个字符开始匹配,若满足则返回,没实现模糊,现在需要做的就是,无论第几个字符与其匹配,都返回,如下:

var opts = $(this).combobox('options');
return row[opts.textField].indexOf(q) >= 0;


$.ajax({
type: "post",
url: 'GetDrpProjectTypeDic.ashx?OperationType=droplist&type=' + r.UAS_Type+'&fields=PTD_Name,PTD_ID&sort=PTD_ID&order=desc',
data: $("#formadd").serialize(),
success: function (obj) {
$('#DrpSYSProjectStatus').combobox({
width: 300,
valueField: 'PTD_ID',
textField: 'PTD_Name',
data: jQuery.parseJSON(obj.Msg),
filter: function (q, row) {
if (row["PinYin"]) {
var opts = $(this).combobox('options');
var tmp = q.toLowerCase();
return row["PinYin"].indexOf(tmp) >= 0 || row[opts.textField].indexOf(tmp) >= 0;
}
else {
var opts = $(this).combobox('options');
return row[opts.textField].indexOf(q) >= 0;
}
}
});
}
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: