【问题标题】:default in extjs combo-boxextjs 组合框中的默认值
【发布时间】:2015-03-05 06:41:31
【问题描述】:

我正在使用 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'(意味着列表中都缺少)

请帮忙

【问题讨论】:

    标签: javascript extjs extjs3


    【解决方案1】:

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

    试试下面的代码

    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 Combo with Local Data

    【讨论】:

      【解决方案2】:

      mode : 'local' 附加到组合配置中。

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

      【讨论】:

        猜你喜欢
        • 2011-08-23
        • 2011-03-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-11-30
        • 1970-01-01
        • 2012-04-07
        相关资源
        最近更新 更多