17

这是我的组合框

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

5 回答 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'));
    }
}
于 2011-07-15T15:21:16.550 回答
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
},

对于远程组合框,您需要插入商店的load事件以在商店加载后选择值。

于 2011-07-15T09:36:27.933 回答
12

您可以像这样使用 value 属性:

value : 'tr'

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

于 2011-07-15T09:26:12.993 回答
0

您可以使用此代码,将其 id 之后的任何 store 元素分配给默认组合框值。

{ 
  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),
},
于 2015-12-08T09:57:53.237 回答
-1

作为替代方案,我需要显示一个本地存储的 Store,这只是监听 afterRender 方法的问题:

listeners: {
    afterRender: function() {
        this.select(01);
    }
}

01在本例中是 Store 中元素的 id (valueField):

areasCenters: {
        data: [{
                id: 01,
                name: 'Todas'
            },
            {
                id: 02,
                name: 'Elegir...'
            }
        ],
        autoLoad: true
}
于 2018-05-29T09:44:04.440 回答