Extjs 商店过滤 - 包括元字符
我有一个具有注释字段(文本区域)的数据存储,并且想要显示满足用户输入(甚至是元字符)的所有注释。
我编写了以下函数来处理此问题:
function notefilter() {
var newfilter = Ext.getCmp('searchnote');
var searchStr = newfilter.getValue();
searchStr = searchStr.replace('?', '\\?').replace('*', '\\*').replace('+', '\\+').replace('{', '\\{').replace('}', '\\}').replace('[', '\\[').replace(']', '\\]').replace('(', '\\(').replace(')', '\\)').replace('|', '\\|').replace('$', '\\$').replace('^', '\\^');
var re = new RegExp(".*" + searchStr + ".*", "ig");
Ext.getCmp('notesgrid').store.filter('Note', re);
}
但是,即使在转义元字符之后,过滤器也无法搜索元字符,但它适用于所有其他字母数字输入。
我错过了什么吗?
提前致谢 !
I have a data store having a Note field (a textarea) and want to display all Notes satisfying a user input (even metacharacters).
I've written the following function to handle this:
function notefilter() {
var newfilter = Ext.getCmp('searchnote');
var searchStr = newfilter.getValue();
searchStr = searchStr.replace('?', '\\?').replace('*', '\\*').replace('+', '\\+').replace('{', '\\{').replace('}', '\\}').replace('[', '\\[').replace(']', '\\]').replace('(', '\\(').replace(')', '\\)').replace('|', '\\|').replace('
However the filter fails to search for metacharacters even after escaping them, but it works are all other alphanumeric input.
Am I missing something ?
Thanks in advance !
, '\\
However the filter fails to search for metacharacters even after escaping them, but it works are all other alphanumeric input.
Am I missing something ?
Thanks in advance !
).replace('^', '\\^');
var re = new RegExp(".*" + searchStr + ".*", "ig");
Ext.getCmp('notesgrid').store.filter('Note', re);
}
However the filter fails to search for metacharacters even after escaping them, but it works are all other alphanumeric input.
Am I missing something ?
Thanks in advance !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最后,让过滤器开始工作。 JavaScript 内置
escape()
&encodeURIComponent()
为我完成了这项工作。我不必以编程方式转义元字符。Finally, got the filter working. JavaScript's built in
escape()
&encodeURIComponent()
did the work for me. I do not have to programatically escape the metachars.