javascript 组合框与 ExtJS 中的 anyMatch 搜索
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17110591/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ComboBox with anyMatch search in ExtJS
提问by Tiago Sippert
I have a ComboBox with a remote store with local filtering.
Instead of the default filtering, by the first characters like %query
, I want to filter with the contains/anyMatch mode like %query%
.
我有一个带有本地过滤的远程存储的 ComboBox。
相反,默认过滤的,由第一字符,例如%query
,我想过滤器与包含/ anyMatch模式类似%query%
。
I tried to solve this with the answers in the question: ExtJs: Search / Filter within a ComboBox, but it didn't worked.
我试图用问题中的答案解决这个问题:ExtJs: Search / Filter within a ComboBox,但它没有用。
Code:
代码:
var users = Ext.create('Ext.form.ComboBox',{
displayField : 'userName',
valueField : 'userName',
queryMode : 'local',
typeAhead : true,
store : Ext.create('Ext.data.Store', {
model : 'User',
proxy : {
type : 'ajax',
url : './user/list',
reader : {
type: 'json',
root: 'data'
}
}
});
});
Thanks!
谢谢!
回答by Tiago Sippert
Just have to add the following code in the Ext.form.field.Combobox
. This works in ExtJs 4.1 that doesn't have the anyMatch
property.
只需要在Ext.form.field.Combobox
. 这适用于没有该anyMatch
属性的ExtJs 4.1 。
listeners : {
beforequery: function(record){
record.query = new RegExp(record.query, 'i');
record.forceAll = true;
}
}
回答by Greendrake
Use anyMatchconfig option since Ext 4.2.1. In earlier versions it looks like you'll need to override doQuery
method in Ext.form.field.ComboBox
just to be able to add that option to the filter instance you'll find in there:
自 Ext 4.2.1 起使用anyMatch配置选项。在早期版本中,您似乎需要覆盖doQuery
方法Ext.form.field.ComboBox
才能将该选项添加到您将在其中找到的过滤器实例中:
me.activeFilter = new Ext.util.Filter({
root: 'data',
anyMatch: true, // <- add this
property: me.displayField,
value: queryString
});
回答by Andre
The modifier g
is more important, for a global search. i
is only for case insensitive search.
g
对于全局搜索,修饰符更为重要。i
仅用于不区分大小写的搜索。
listeners : {
beforequery: function(record){
record.query = new RegExp(record.query, 'ig');
}}