Extjs 4 combobox default value

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

    You can either put the logic directly into the callback, or set up a function to handle all stores.

    var store1 = Ext.create('Ext.data.Store', {
        ...
        autoLoad: {
            callback: initData 
        }
    });
    
    var store2 = Ext.create('Ext.data.Store', {
        ...
        autoLoad: {
            callback: initData 
        }
    });
    
    var myComboStores = ['store1', 'store2']
    
    function initData() {
        var loaded = true;
        Ext.each(myComboStores, function(storeId) {
            var store = Ext.StoreManager.lookup(storeId);
            if (store.isLoading()) {
                loaded = false;
            }
        }
        if(loaded) {
            // do stuff with the data
        }
    }
    

    =====================

    For those reading, the value config/property on your 'combo' object should be set to some value so the combo box gets an initial value. You have already done this. The value 'all' also needs to be in your store before it'll set it as the default.

    value: 'all'
    

    Also, it's good practice to set a value for the valueField config, which you've done already. If you don't, the select listener won't get the correct value when calling combo.getValue().

提交回复
热议问题