View Full Version : Finding out which ExtJS class a component is instantiated from

5 Aug 2009, 7:57 AM

I'm new-ish to ExtJS and we have a lot of code which sometimes creates objects using the { xtype: 'footype' } syntax and sometimes using new My.FooType(). Is there any way for me to get that component and find out which ExtJS class corresponds to that xtype?

Or, put another way, I know I can do the following to find the xtype of a component:

var t = new Ext.form.TextField();

But if t was created using {xtype:'textfield'} how would I find out in javascript that t is really created from Ext.form.TextField?


5 Aug 2009, 7:59 AM
It makes no diff. A TextField is a TextField.

5 Aug 2009, 8:12 AM
it looks like what you mean is how do you get the Ext component from a dom representation?

Even if you have the id of the element or another way of getting the dom element, Ext.get only gets the Ext.Element.

Check out the Component.js file. It registers components with the ComponentMgr, so querying that in some way will probably give you the bridge back to the component from the DOM element.

ok, try "Ext.ComponentMgr.get(elementid);"

5 Aug 2009, 8:20 AM
"Ext.ComponentMgr.get(elementid);" is longhand for "Ext.getCmp(elementid)" which you're probably already familiar with, but Ext.getCmp(id) will only return the component if the id was specified explicitly. It's tricky to get from an arbitrary field or div back to it's corresponding component.