我有一个包含某些记录的网格,其上方有一个文本字段。文本字段与网格连接,以便每次出现 keyup 事件时,它都会转到过滤器函数,以便仅显示包含用户输入的字符的记录。问题是,现在它只匹配来自记录字符串名称的起始字符,但是 id 希望能够过滤所有包含记录字符串名称中任意位置键入的字符的记录。
截图:- /image/mXUCk.jpg
第一个图像显示记录,第二个图像显示当我输入“c”时过滤的结果,第三个图像显示当我按“p”时它不会返回任何结果,但我希望它返回“GPL Products” ”和“报告期”,因为它们都包含“p”。
这是代码:-
onDimensionFilterTextBoxKeyUp: function (filterTxtBox, evntObj, eOpts) {
var dimStore = this.getDimensionStoreStore();
//get new value
var searchValue = filterTxtBox.getValue();
//var regex = /searchValue*/;
//clear previous search value
dimStore.clearFilter();
if (!Ext.isEmpty(searchValue)) {
//load filtered data
dimStore.filter('DimensionName', searchValue);
}
}
我尝试使用/searchValue*/创建正则表达式模式,但使用它只会破坏过滤器,并且不会返回任何结果。
最佳答案
试试这个:
re = new RegExp(searchValue, ignoreCase ? 'i' : '');
store.filter(field, re);
关于regex - 在 Ext JS 中搜索模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9686420/