Changing elements in initComponent ()

I create several elements in initComponent() The problem is that this.items somehow refers to a class variable, not an instance variable.

So, when I make two instances, I get two buttons.

 items: [], initComponent: function() { this.items.push( { xtype: 'button', ... }) ; this.callParent( arguments ); } 

Since I have to use push, every time new elements are introduced.

Is there some instance equivalent to this.items where I can change the definition before the button is created or do I need to check for duplicates manually?

+4
source share
2 answers

You should not return this.callParent( arguments );

Only this is enough:

 initComponent: function() { var me = this; me.items = { xtype: 'button', ... }; //Are you sure items is filled up here? me.callParent(); } 

Also, if you write your โ€œcomponentโ€ and want to pass parameters to Ext.create , I always do the following:

 constructor: function (config) { var me = this; Ext.apply(me, config); me.callParent(); } 

This will overwrite the declaration of your objects in your class with the one you pass to Ext.create()

+6
source

You can reload the constructor and configure the configuration there:

 constructor: function(config) { config.items.someButton = { xtype: 'button', ... }; this.callParent([config]); } 
+1
source

All Articles