Extjs 4 combobox default value

后端 未结 9 1529
时光取名叫无心
时光取名叫无心 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:58

    Specifying the 'value' parameter in the config is a correct way to set the default values for comboboxes.

    In your example, just set forceSelection:false, it will work fine.

    In case you want to set forceSelection:true, you should make sure the data returned from your store contains an item which has the value equaling to your default value ('all' in this case).Otherwise, it'll be an empty text by default. To be more clearly, please replace your dirValuesStore definition by this:

        var dirValuesStore = Ext.create('Ext.data.Store', {
            fields: ['id', 'name'],
            data: [
                {id: 'all', name: 'All'},
                {id: '1', name: 'Name 1'},
                {id: '2', name: 'Name 2'},
                {id: '3', name: 'Name 3'},
                {id: '4', name: 'Name 4'}
            ]
        })
    

    You will see it works!

提交回复
热议问题