Extjs 4 combobox default value

后端 未结 9 1511
时光取名叫无心
时光取名叫无心 2020-12-06 04:41

I\'m migrating my application from ExtJs 3 to 4 version. I have several comboboxes at my formPanel, and previously I\'ve used hiddenName and all that stuff to submit valueFi

9条回答
  •  粉色の甜心
    2020-12-06 04:45

    The best way for doing this is that listen to afterrender event and then set the default value in the callback function.

    See this code:

    new Ext.form.field.ComboBox({
        //This is our default value in the combobox config
        defaultValue: 0,
        listeners: {
            //This event will fire when combobox rendered completely
            afterrender: function() {
               //So now we are going to set the combobox value here.
               //I just simply used my default value in the combobox definition but it's possible to query from combobox store also.
               //For example: store.getAt('0').get('id'); according to Brik's answer.
               this.setValue(this.defaultValue);    
            }
        }
    });
    

提交回复
热议问题