Extjs 4 combobox default value

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

    I noticed your Combo config has queryMode: 'local'. That value is intended for when your data is stored locally in an array. But your model is using an AJAX proxy. Could it be that this confuses Ext so it can't find the default value you're trying to set? Try removing queryMode so it defaults to the value of 'remote' (or set it explicitly.)

    UPDATE: I was migrating my own app from Ext3 to 4 right after posting the above, and I ran into the exact same problem. I'm sure queryMode is part of it, but the main problem is that the combobox doesn't have the data needed yet at the time it's rendered. Setting value does give it a value but there's nothing in the data store yet to match it with, so the field appears blank. I discovered that the autoLoad property can also specify a callback function to be used when the data is loaded. Here's what you could do:

    store: new Ext.data.Store({
        model: 'MyModel',
        autoLoad: {
            scope: this,
            callback: function() {
                var comboBox = Ext.getCmp("MyComboBoxId");
                var store = comboBox.store;
    
                // set the value of the comboBox here
                comboBox.setValue(blahBlahBlah);
            }
        }
        ...
    })
    

提交回复
热议问题