PDA

View Full Version : call parent method



alberto01
13 Oct 2010, 10:30 AM
Sorry aganin,
i have this toolbar:


mainToolbarUi = Ext.extend(Ext.Toolbar, {
initComponent: function() {
this.items = [
{
xtype: 'myButtons',
page: 'centerPanel',
text: 'Anagrafica fornitori'
handler: function(){
MyViewport.changeMenu();
}
},
.......
Ext.reg('mainToolbar', mainToolbar);


the toolbar is called from the MyViewport class in this way:


MyViewportUi = Ext.extend(Ext.Viewport, {
layout: 'border',
initComponent: function() {
this.items = [
{
region: 'north',
split: true,
id: 'northPanel',
xtype: 'mainToolbar'
},
{
xtype: 'panel',
region: 'center',
id: 'centerPanel',
items: [
{
xtype: 'centerPanel'
}
]
}
];
MyViewportUi.superclass.initComponent.call(this);
}
});

and then main class

MyViewport = Ext.extend(MyViewportUi, {
initComponent: function() {
MyViewport.superclass.initComponent.call(this);

// recuperi i pannelli che mi interessano
this.content = this.getComponent('centerPanel');
this.northBbar = this.getComponent('northPanel').getBottomToolbar();
/*
this.northBbar.getComponent(0).on('click',function(){
this.changeMenu('centerPanel');
}, this);

this.northBbar.getComponent(2).on('click',function(){
this.changeMenu('centerPanel2');
}, this);
*/
},

changeMenu: function(object){
this.content.removeAll();
this.content.add({xtype: object});
this.content.doLayout();
}

});



When I click the 1st button i get an error

Uncaught TypeError: Object function (){G.apply(this,arguments)} has no method 'changeMenu'

How can I call the changeMenu, why it cannot recognise it?

tnxxxx in advance

Condor
13 Oct 2010, 10:55 AM
MyViewport is a class and not an instance.

You will have to find a way to locate the MyViewportUi instance from the toolbar button handler.

Something like (not sure if it works):

handler: function(btn){
var viewport = btn.findParentByType('viewport');
viewport.changeMenu();
}

plalx
13 Oct 2010, 11:06 AM
Like Condor said, the method is not accessible because Ext.extend adds members to the prototype, not the class.

E.g.



MyObject = Ext.extend(Object, {
getText: function() {return 'text';}
});

//MyObject.getText is undefined....
//MyObject.prototype.getText is defined

//So, if we create an instance of MyObject

var o = new MyObject();

console.log(o.getText()); //This will work now.