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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 07:07:45  来源:igfitidea点击:

ComboBox with anyMatch search in ExtJS

javascriptextjscomboboxextjs4

提问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 anyMatchproperty.

只需要在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 doQuerymethod in Ext.form.field.ComboBoxjust 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 gis more important, for a global search. iis only for case insensitive search.

g对于全局搜索,修饰符更为重要。i仅用于不区分大小写的搜索。

listeners   : {
beforequery: function(record){  
    record.query = new RegExp(record.query, 'ig');
}}