Extjs4 Combobox还有其他选项

jay*_*ode 3 extjs extjs4

我希望创建一个加载商店的组合框,但也希望在其上添加一些预定义数据.可能吗?

Zan*_*ngo 5

我想这就是你需要的:

Ext.define('App.widget.MyCombo', {
    extend  : 'Ext.form.field.ComboBox',
    displayField: '...',
    valueField  : '...',
name : '...', alias : 'widget.mycombo', fieldLabel : 'My Custom combo',

initComponent: function() {
    var me = this;

    me.store = Ext.create('Ext.data.Store', {
        model : '...',
        proxy : {
            type : '...',
            reader: '...'
        }
    });

    /*After data is loaded append some predefined records.*/    
    me.store.on('load', function() {
        /*Indicates that data must be appended to already loaded data.*/
        var append = true;

        me.store.loadData([{id : -1, value : 'Default'}, 
                           {id: -2, value: 'Second Default'}], append);
    });

    me.callParent();
}
Run Code Online (Sandbox Code Playgroud)

});

Ext.define('App.widget.MyCombo', {
    extend  : 'Ext.form.field.ComboBox',
    displayField: '...',
    valueField  : '...',
name : '...', alias : 'widget.mycombo', fieldLabel : 'My Custom combo',

initComponent: function() {
    var me = this;

    me.store = Ext.create('Ext.data.Store', {
        model : '...',
        proxy : {
            type : '...',
            reader: '...'
        }
    });

    /*After data is loaded append some predefined records.*/    
    me.store.on('load', function() {
        /*Indicates that data must be appended to already loaded data.*/
        var append = true;

        me.store.loadData([{id : -1, value : 'Default'}, 
                           {id: -2, value: 'Second Default'}], append);
    });

    me.callParent();
}
Run Code Online (Sandbox Code Playgroud)

});