繁体   English   中英

默认在extjs组合框中

[英]default in extjs combo-box

我正在使用extjs 3.4

这是我的代码:

Ext.onReady(function() {
        var myPanel = new Ext.Panel({
            renderTo : document.body,
            height   : 500,
            width    : 1000,
            title    : 'Simple Panel',
            html     : 'This is my content',
            frame    : true,
            items: {
            layout: 'form',
            width: 200,
            labelAlign: 'top',
            style: 'margin-top: 5px;',
            items: {        
                xtype: 'combo',
                id: 'x',
                width: 115,
                listWidth: 115,
                fieldLabel: '<b>My combo</b>',
                labelStyle: 'font-size: 11px;',
                style: 'margin-left:20px',
                labelSeparator: '',
                forceSelection: true,
                value: 'A',     
                store: ['A', 'B', 'c'],                 
                autoSelect: true                    
            }
    }
        });

    }); 

我想把'A'作为默认值......现在它只在组合框中显示'A'...并且'B'和'c'缺失(表示列表中缺少两个)

请帮忙

您没有正确定义商店或告诉组合商店中使用哪些字段。

请尝试下面的代码

var myPanel = new Ext.Panel({
    renderTo: Ext.getBody(),
    height: 500,
    width: 1000,
    title: 'Simple Panel',
    html: 'This is my content',
    frame: true,
    items: {
        layout: 'form',
        width: 200,
        labelAlign: 'top',
        style: 'margin-top: 5px;',
        items: {
            xtype: 'combo',
            id: 'x',
            width: 115,
            listWidth: 115,
            fieldLabel: '<b>My combo</b>',
            labelStyle: 'font-size: 11px;',
            style: 'margin-left:20px',
            labelSeparator: '',
            forceSelection: true,
            typeAhead: true,
            triggerAction: 'all',
            lazyRender:true,
            mode: 'local',
            value: 'A',
            store: new Ext.data.ArrayStore({
                id: 0,
                fields: [
                    'myId',
                    'displayText'
                ],
                data: [['A', 'A'], ['B', 'B'],  ['C', 'C']]
            }),
            valueField: 'myId',
            displayField: 'displayText',
            autoSelect: true
        }
    }
});

需要注意的主要差异:

mode: 'local',
store: new Ext.data.ArrayStore({
            id: 0,
            fields: [
                'myId',
                'displayText'
            ],
            data: [['A', 'A'], ['B', 'B'],  ['C', 'C']]
        }),
        valueField: 'myId',
        displayField: 'displayText'

参考: ExtJs 3.4组合本地数据

追加mode : 'local'到combo配置。

可以将combobox与数组一起使用而不是存储( http://docs.sencha.com/extjs/3.4.0/#!/api/Ext.form.ComboBox-cfg-store

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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