如何在Ext Js中自动选择(显示)下拉框中的第一个值?

17
这是我的下拉框。
{
    xtype: 'combo', 
    fieldLabel: LANG.LOGIN_LANG,
    id : 'lang', 
    store: [
        ['tr','Türkçe'],
        ['ru','Русский'],
        ['en','English']
    ],
    mode: 'local',
    triggerAction: 'all',
    selectOnFocus:true
},

1
在创建下拉框之前,存储器是否已加载?在给定的示例中,Satish Kumar的答案是您的解决方案... - Zango
5个回答

31

通常情况下,当我想选择存储的第一个值时,我会使用以下方法:

xtype: 'combo', 
fieldLabel: 'prov',
id : 'lang', 
store:[['tr','Türkçe'],['ru','Русский'],['en','English']],
mode: 'local',
triggerAction: 'all',
selectOnFocus:true,
listeners: {
    afterrender: function(combo) {
        var recordSelected = combo.getStore().getAt(0);                     
        combo.setValue(recordSelected.get('field1'));
    }
}

23
{
  xtype: 'combo', 
  fieldLabel: LANG.LOGIN_LANG,
  id : 'lang', 
  store:[['tr','Türkçe'],['ru','Русский'],['en','English']],
  mode: 'local',
  triggerAction: 'all',
  value: 'tr',
  selectOnFocus:true
},

对于远程组合框,您需要插入到 store 的 load 事件中,在存储加载后选择值。


12
你可以这样使用value属性:

value: 'tr'

然后它将默认显示第一个值。


0
您可以使用此代码,将任何存储元素分配给默认组合框值后的ID。
{ 
  xtype: 'combobox',
  forceSelection: true,
  allowBlank: true,
  typeAhead: true,
  queryMode: 'local',
  colspan: 3,
  id: 'filter_column_c',
  style: {'margin': '5px 15px 15px 30px'},
  fieldLabel: 'Column',
  valueField: 'column',
  displayField: 'name',
  store: nomStores["storeCombo"],
  value: nomStores["storeCombo"].getById(1),
},

-1
作为一种替代方案,我需要展示一个本地存储的 Store,只需要监听 afterRender 方法即可实现:
listeners: {
    afterRender: function() {
        this.select(01);
    }
}

01在这种情况下是存储中元素的ID(valueField):

areasCenters: {
        data: [{
                id: 01,
                name: 'Todas'
            },
            {
                id: 02,
                name: 'Elegir...'
            }
        ],
        autoLoad: true
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接