PDA

View Full Version : calling parent method from child instance



dha
14 Jan 2014, 3:15 PM
I have a grid I need to display multiple times with different data.
I created a view like this:
Ext.define('my.view.A', {
extend: 'Ext.grid.Panel',
alias: 'widget.A',
constructor: function(config){
this.initConfig(config)
this.callParent(arguments);
},
config:{
columns:[{
xtype:'combo',
cls: 'parentcls',

listeners:{
select: function(){
console.log('selected from parent');
}
}
}]
}

});




I create instances of it like this:
Ext.create('my.view.A', {
columns:[{
xtype:'combo',
cls: 'childcls',
listeners:{
select:function(){
/*
In some columns I want this function to just call the function defined in the parent class.
Can I do that from here?
*/
}
}
}]
})

Thanks in advance!

KJedi
15 Jan 2014, 1:18 AM
Hi,

combo in the my.view.A definition is an instance of Ext.form.field.ComboBox. When you instantiate the my.view.A, you put another instance of the combobox. There is no inheritance.

If you need to implement inheritance of comboboxes, you need to define your custom combo and then extend it. When you bind the event, do not create anonymous function. Instead, define a method e.g. onSelectValue and put your logic there. When you create a child class, override this method.
This way select event in both child and parent would call onSelectValue, but logic would be different if needed.

If you describe your initial task, we could help better.

palakurthivishal
15 Jan 2014, 8:57 AM
Hello dha,
If what you need is just to call a function which is associated to an event of a component, just query the component and fire the event of it. Just like this, cmp.fireEvent('event', args);
Or if it is that you need to call a function defined in a parent class, just instantiate an object of parent and call the function. Say,
var parentObj = Ext.create('ParentNamespace');
parentObj.method1();