PDA

View Full Version : How do I pass in a component to a class?



wxkevin
1 Mar 2013, 5:02 AM
I don't quite understand how to extend classes with local variables, constructors, etc...I have read the documentation but it either doesn't work or is not making sense.

In a form I have a button that when selected creates a new Window component that I have extended. This window provides selections and stuff for the user and creates a string that I would like to display in a form. I want to reuse this window component so that it places the created string into a label that I provide at instantation time. So basically I want to give the window the label component where the result should be placed. How do I do this? Do I use a config object or constructor? If so, specifically how do you do this?

mitchellsimoens
4 Mar 2013, 8:19 AM
You need a reference to the label on the window so that you can take action on it...


Ext.define('MyWindow', {
extend : 'Ext.window.Window',
xtype : 'mywindow',

labelComponent : null,

someMethod : function() {
this.labelComponent.doSomething('abcd');
}
});


Ext.create('MyWindow', {
labelComponent : someLabel
});

wxkevin
7 Mar 2013, 8:46 AM
Here is how we ended up doing this in case anyone comes here through search. We actually instantiate our window with the component where we want to place the resultant string.


Ext.define('MyWindow', {
extend: 'Ext.Window',
alias: 'widget.mywindow',

.....

config: {
comp: '' // Component to update
},

constructor: function(config) {
this.superclass.constructor.call(this, config);
var anotherComponent = Ext.create('....');
this.items.add(anotherComponent);
}

...
}

And this is how we created an instance of the window above:


....

},{
xtype: 'button',
text: 'Select',
handler: function() {
Ext.create('MyWindow', {
comp: 'idOfComponent'
}).show();
}
},{

....