ext.net中ComboBox空间实现模糊查询

时间:2021-04-03 23:03:53

ComboBox中的属性添加Mode="Local"可以实现第一个字的模糊查询但是搜索中间的字无法实现

现提供一下方法使用正则表达式实现全模糊查询

<ext:ComboBox ID="ComboBox1" runat="server" DisplayField="MingCheng" ValueField="Id" StoreID="Employ" Width="">
<Listeners>
<BeforeQuery Fn="bq" />
</Listeners>
</ext:ComboBox>
var bq = function (e) {
var combo = e.combo;
if (!e.forceAll) {
var input = e.query;
// 检索的正则
var regExp = new RegExp(".*" + input + ".*");
// 执行检索
combo.store.filterBy(function (record, id) {
// 得到每个record的项目名称值
var text = record.get(combo.displayField);
return regExp.test(text);
});
combo.expand();
return false;
}
}