Vishal Zanzrukia
Vishal Zanzrukia

Reputation: 4973

Need to pass object from child to parent Class in ExtJS

I am new in extJs. so I need some help for pass object from Child component/class to Parent. My code is given below.

My parent class is

  Ext.define('My.Parent', {
     extend: 'Ext.panel.Panel',
     initComponent:function()
     {
// suppose I want object here which passes from child.
       this.callParent(arguments);
     }
 });

and my child class is

 Ext.define('My.Child', {
    extend: 'My.Parent',
    initComponent:function()
    {   
// Suppose I have one object like var Json = {name:'John'}; 
// and I want to pass this object in parent class's init method.
       this.callParent(arguments);
    }

});

can anybody help me? thank you in advance.

Upvotes: 0

Views: 1293

Answers (1)

rixo
rixo

Reputation: 25041

Just store it in the instance using this. This is standard OOP.

Ext.define('My.Parent', {
    extend: 'Ext.panel.Panel',
    initComponent:function()
    {
        alert(this.myObject);

        this.callParent(arguments);
    }
});

Ext.define('My.Child', {
    extend: 'My.Parent',
    initComponent:function()
    {   
        var Json = {name:'John'};
        this.myObject = Json;

        this.callParent(arguments);
    }
});

Upvotes: 3

Related Questions