BigJobbies
BigJobbies

Reputation: 509

ExtJS Cannot read property 'add' of undefined

I have an ExtJS / PHP app that im working on and i keep running into the error

Uncaught TypeError: Cannot read property 'add' of undefined

The lines that im working with are as follows;

parentPanel = Ext.getCmp('<?php echo $thename; ?>_<?php echo $formDetails ?>');
parentPanel.add(theGridPanel);
parentPanel.doLayout();

Im not exactly whats going on.

Any help would be awesome

Upvotes: 1

Views: 1673

Answers (2)

Shahbaz
Shahbaz

Reputation: 392

The Ext.getCmp() is meant to find an element in the DOM by its ID.

So just make sure you are passing the right id and in the right case to Ext.getCmp().

If you need, please check the docs here

EDIT

Extending my answer as I agree with the point mentioned by @scebotari66 in the comments.

Ext.getCmp() is meant to find extjs components only and not any html element in the DOM.

So that means Ext.getCmp() is not equal to document.getElementById()

What I mentioned 'find an element in the DOM' is just for easier understanding of the task performed by the command getCmp() whereas in actual it fetches the component with the given ID from the Ext.ComponentManager and not from the DOM

Upvotes: 3

Adelin
Adelin

Reputation: 8209

JavaScript tries to call .add() on an undefined. To be more exact. this line:

Ext.getCmp('<?php echo $thename; ?>_<?php echo $formDetails ?>');

returns undefined.

So make sure you correct your query.

Upvotes: 2

Related Questions