1

I am using extJs 3.4 combobox autocomplete, i want autocomplete search to work interchangeably of characters position. For example when i type 'v' it autocompletes to vanessa (it is working well) but when i type 'a' it doesnt autocomplete. i would like to autocomplete by any character(that exist) in any site. Something like this a - vanessa,daniela s - vanessa or ssa - vanessa

This is my code

xtype: 'combo', 
fieldLabel: 'prov',
id : 'lang', 
store:[['tr','vanessa'],['ru','daniela'],['en','English']],
mode: 'local', 
triggerAction: 'all',
selectOnFocus:true,
listeners: {
afterrender: function(combo) {
    var recordSelected = combo.getStore().getAt(1);                     
    combo.setValue(recordSelected.get('field1'));
}

}

Thank you and i apologize for my grammar it isn't very good.

4

1 回答 1

1

您必须稍微改变该doQuery方法的行为。正如您在代码中看到的那样,我们很幸运,因为有一个事件让我们有机会做到这一点而不会过多地破解组合:) 此外,如果我们将正则表达式传递给 store 的filter方法,它将忽略它的其他参数(我们本来想通过的一个是anyMatch......但组合并没有给我们机会)。

所以,我们只需要挂钩这个事件并将query字符串属性转换为正则表达式!就是这样:

Ext.create({
    xtype: 'combo',
    renderTo: Ext.getBody(),
    fieldLabel: 'prov',
    id: 'lang',
    store: [
        ['tr', 'vanessa'],
        ['ru', 'daniela'],
        ['en', 'English']
    ],
    mode: 'local',
    triggerAction: 'all',
    selectOnFocus: true,
    listeners: {
        beforequery: function(q) {
            // we don't want to crash if there's nothing in there
            if (q.query) {
                // we need the length later in the doQuery function,
                // for respecting minChars
                var length = q.query.length;
                q.query = new RegExp(Ext.escapeRe(q.query));
                // pretend I am a string, eh eh
                q.query.length = length;
            }
        }
    }
});

您可能希望重写Ext.form.ComboBox该类以将其添加为选项(我称之为anyMatch),因为这是一个非常常见的要求。

于 2013-09-20T15:29:32.330 回答