IUnknown
IUnknown

Reputation: 9809

Customizing shared component

Ext.define('RevenuePanel', {     extend: 'Ext.panel.Panel',
items: [ 
..........        
Ext.create('Ext.button.Button', {text: 'Button'})     ] 
}); 

In this case,I believe the items property is copied to the class's prototype.
What is the good programming practice/s to allow the panel to have custom behaviour for its items at multiple containers which would use it within the application?

We are on Ext3.4x

Upvotes: 0

Views: 43

Answers (1)

sra
sra

Reputation: 23973

I assume that you just want to add more items, without overriding the predefined.

Ext.define('RevenuePanel', {     
    extend: 'Ext.panel.Panel',
    initComponent: function(){
        var me = this,
            newItems = me.items,
            defaultItems, items;
        // apply your default items
        defaultItems = [{xtype:'button', text:'Button'}];
        // check if there are new items defined for this instance
        if(typeof newItems != 'undefined') {
            items = defaultItems.concat((newItems instanceof Array ) ? newItems : [newItems]);
        } else {
            items = defaultItems;
        }
        // override the items
        me.items = items;

        me.callParent(arguments);
    }

}); 

Upvotes: 2

Related Questions