在ExtJs中重用相同的组件

在ExtJs中重用相同的组件,extjs,store,gridpanel,Extjs,Store,Gridpanel,我想要的是能够同时创建面板的两个实例,但是当我执行类似于newdashboard.NotificationPanel()的操作时;新建Dashboard.NotificationPanel()第一个未显示网格结果。我怀疑它与initComponent stage有某种联系,特别是两个对象通过引用使用同一个store对象。如果我错了,请纠正我,或者指出我的错误。提前谢谢 Dashboard.NotificationPanel = Ext.extend(Ext.grid.GridPanel, {

我想要的是能够同时创建面板的两个实例,但是当我执行类似于
newdashboard.NotificationPanel()的操作时;新建Dashboard.NotificationPanel()第一个未显示网格结果。我怀疑它与initComponent stage有某种联系,特别是两个对象通过引用使用同一个store对象。如果我错了,请纠正我,或者指出我的错误。提前谢谢

Dashboard.NotificationPanel = Ext.extend(Ext.grid.GridPanel, {
    columns: [...],
    view: new Ext.grid.GridView({
        forceFit: true,
        enableRowBody: true,
        ignoreAdd: true,
        emptyText: 'No Notifications to display'
    }),
    initComponent: function () {
        var store = new Ext.data.Store({
            url: '...',
            autoLoad: true,
            reader: new Ext.data.XmlReader({
                record: 'result',
                id: 'id'
            }, ['c_case_number', 'c_creator', 'c_date_created', 'c_notification_condition', 'c_message'])
        });
        var config = {
            store: store,
            bbar: new Ext.PagingToolbar({
                pageSize: 10,
                store: store,
                displayInfo: true,
                displayMsg: 'Displaying notifications {0} - {1} of {2}',
                emptyMsg: "No Notifications to display"
            })
        }
        Ext.apply(this, Ext.apply(this.initialConfig, config));

        Dashboard.NotificationPanel.superclass.initComponent.call(this);

    }

});

它不能处理两个实例的原因是视图和柱应用于原型,而不是网格的实际实例。它们本质上是在所有实例之间共享的,这不是预期的行为。除非需要共享行为,否则不要在原型上放置非基本体对象。改为这样做:

Dashboard.NotificationPanel = Ext.extend(Ext.grid.GridPanel, {
initComponent : function() {
    var store = new Ext.data.Store({
        url : '...',
        autoLoad : true,
        reader : new Ext.data.XmlReader({
                    record : 'result',
                    id : 'id'
                }, ['c_case_number', 'c_creator', 'c_date_created',
                        'c_notification_condition', 'c_message'])
    });
    var config = {
        columns : [...],
        view : new Ext.grid.GridView({
            forceFit : true,
            enableRowBody : true,
            ignoreAdd : true,
            emptyText : 'No Notifications to display'
        }),
        store : store,
        bbar : new Ext.PagingToolbar({
                    pageSize : 10,
                    store : store,
                    displayInfo : true,
                    displayMsg : 'Displaying notifications {0} - {1} of {2}',
                    emptyMsg : "No Notifications to display"
                })
    }
    Ext.apply(this, Ext.apply(this.initialConfig, config));

    Dashboard.NotificationPanel.superclass.initComponent.call(this);

}
});

Ext.apply(this, Ext.apply(this.initialConfig, config))
Ext 3中是否有冗余代码,请改用:

Ext.apply(this, config)

它不能处理两个实例的原因是视图和柱应用于原型,而不是网格的实际实例。它们本质上是在所有实例之间共享的,这不是预期的行为。除非需要共享行为,否则不要在原型上放置非基本体对象。改为这样做:

Dashboard.NotificationPanel = Ext.extend(Ext.grid.GridPanel, {
initComponent : function() {
    var store = new Ext.data.Store({
        url : '...',
        autoLoad : true,
        reader : new Ext.data.XmlReader({
                    record : 'result',
                    id : 'id'
                }, ['c_case_number', 'c_creator', 'c_date_created',
                        'c_notification_condition', 'c_message'])
    });
    var config = {
        columns : [...],
        view : new Ext.grid.GridView({
            forceFit : true,
            enableRowBody : true,
            ignoreAdd : true,
            emptyText : 'No Notifications to display'
        }),
        store : store,
        bbar : new Ext.PagingToolbar({
                    pageSize : 10,
                    store : store,
                    displayInfo : true,
                    displayMsg : 'Displaying notifications {0} - {1} of {2}',
                    emptyMsg : "No Notifications to display"
                })
    }
    Ext.apply(this, Ext.apply(this.initialConfig, config));

    Dashboard.NotificationPanel.superclass.initComponent.call(this);

}
});

Ext.apply(this, Ext.apply(this.initialConfig, config))
Ext 3中是否有冗余代码,请改用:

Ext.apply(this, config)

附加提示:根据经验,只使用简单的数据类型(数字、字符串、布尔值)或函数作为
Ext.extend
的第二个参数的成员。谢谢pllee,您的答案很有帮助。感谢你花时间回答我的问题。嘿,彭彭,你这是什么意思?额外提示:根据经验法则,只使用简单的数据类型(数字、字符串、布尔值)或函数作为
Ext.extend
的第二个参数的成员。谢谢你,你的回答很有帮助。谢谢你花时间回答我的问题。嘿,彭彭,你这是什么意思?