如何将editable设置为false时过滤组合框

时间:2013-11-18 09:19:00

标签: extjs extjs3

嗨,我有一个像这样的组合框

               var combo = new Ext.form.ComboBox({
                        store: store,
                        displayField:'state',
                        typeAhead: true,
                        mode: 'local',
                        editable:false,
                        forceSelection: true,
                        triggerAction: 'all',
                        emptyText:'Select a state...',
                        selectOnFocus:true,
                        renderTo:document.body

                    });

当它可编辑为true时,当我在组合字段中输入时,列表将根据输入的字符进行过滤。

我想在config editable设置为false时实现相同的目标。

1 个答案:

答案 0 :(得分:2)

请尝试以下代码:

Ext.onReady(function(){
Ext.namespace('Ext.exampledata');
Ext.exampledata.states = [
    [ 'Alabama' ],
    [ 'Alaska' ],
    [ 'Arizona'],
    [ 'Arkansas' ],
    [ 'California'],
    [ 'Colorado'],
    [ 'Connecticut'],
    ['Delaware'],
    [ 'District of Columbia'],
    [ 'Florida'],
    [ 'Georgia'],
    [ 'Hawaii'],
    [ 'Idaho'],
    [ 'Illinois'],
    [ 'Indiana'],
    [ 'Iowa'],
    [ 'Kansas'],
    [ 'Kentucky'],
    [ 'Louisiana'],
    [ 'Maine'],
    [ 'Maryland'],
    ['Massachusetts'],
    [ 'Michigan'],
    [ 'Minnesota'],
    [ 'Mississippi'],
    [ 'Missouri'],
    ['Montana'],
    [ 'Nebraska'],
    [ 'Nevada'],
    [ 'New Hampshire'],
    [ 'New Jersey'],
    [ 'New Mexico']

];

var store = new Ext.data.ArrayStore({
    fields: ['state'],
    data : Ext.exampledata.states 
});
                    var combo = new Ext.form.ComboBox({
                        store: store,
                        displayField:'state',
                        typeAhead: true,
                        mode: 'local',
                        editable:false,
                        forceSelection: true,
                        triggerAction: 'all',
                        emptyText:'Select a state...',
                        selectOnFocus:true,
                        listeners: {
                             'keyup': function(field,event) {
                                  var key = String.fromCharCode(event.getKey());
                                  var filter=/^[a-zA-Z]+$/;
                                  var test_bool = filter.test(key);
                                  if(test_bool==true){
                                      combo.clearValue();
                                      combo.doQuery(key);
                                  }
                             },
                            'expand':function(combo){
                              combo.clearValue();
                             }
                         },
                        renderTo:document.body

                    });
});