组合框中的默认选定值

时间:2015-09-21 10:10:04

标签: javascript extjs

我有一个组合框,我有两种类型的笔记本电脑,toshiba和hp。加载时,选择默认值为空。我想将默认选择值设为Toshiba,以便最初选择它。例如在HTML"选择"。有什么帮助吗?

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),
        });

1 个答案:

答案 0 :(得分:1)

只需将combobox的{​​{3}}设置为与商店中的值对应的值即可。因此,如果您将valueField设置为'abbr',则可以使用商店'abbr'的其中一个值。

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