简体   繁体   中英

Default selected value in a combobox

I have a combobox that I have in it two types of laptops, toshiba and hp. On load the selection default value is nothing. I want to make the default selected value Toshiba, so that it's initially selected. Such as in HTML "selected". Any help please?

laptops = Ext.create('Ext.data.Store', {
        fields: ['abbr','value', 'name'],
        data : [
            {"abbr":"tosh","value":"toshibatypes", "name":"Toshiba"},
            {"abbr":"hp","value":"hptypes", "name":"HP"}
        ]
    });



    toshibatypes = Ext.create('Ext.form.Panel', {
            xtype: 'radiogroup',
            defaultType: 'radio', 
            layout: 'hbox',
            border:false,
            id: 'toshiba',
            width:'100%',

            items: [ 
            {
                checked: true,
                boxLabel: 'Toshiba 1',
                name: 'toshibas',
                inputValue: 'toshiba1',
                xtype:'radiofield'
            }, 
            {
                boxLabel: 'Toshiba 2',
                name: 'toshibas',
                inputValue: 'toshiba2',
                xtype:'radiofield'
            }
        ]
    });



    hptypes = Ext.create('Ext.form.Panel', {
            xtype: 'radiogroup',
            defaultType: 'radio', 
            layout: 'hbox',
            border:false,
            id: 'hp',
            width:'100%',

            items: [ 
            {
                checked: true,
                boxLabel: 'HP 1',
                name: 'hps',
                inputValue: 'hp1',
                xtype:'radiofield'
            }, 

            {
                boxLabel: 'HP 2',
                name: 'hps',
                inputValue: 'hp2',
                xtype:'radiofield'
            }]
    });



        laptoptypes = Ext.create('Ext.form.ComboBox', {
            store: laptops,
            queryMode: 'local',
            displayField: 'name',
            valueField: 'abbr',
            editable:false,
            width: 100,
            onchange:onSelectChange(this),
        });

Just set the value of the combobox to a value corresponding to a value from the store. So if you set valueField to 'abbr' , one of the values of 'abbr' of the store can be used.

laptoptypes = Ext.create('Ext.form.ComboBox', {
    store: laptops,
    queryMode: 'local',
    displayField: 'name',
    valueField: 'abbr',
    value: 'tosh',
    editable:false,
    width: 100,
    onchange:onSelectChange(this),
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM