View Full Version : getting component

13 Sep 2012, 8:31 AM
I got a lot of way of getting a component inside a controller in MVC.

But what is the difference among them.Which is more proper.
like. Ext.widget()

13 Sep 2012, 10:22 AM
Ext.widget() <- creates generic component
Ext.getCmp() <- get id of component if known; not recommended; use query and itemId
getComponent() <- ok if looking for sub component
this.getViewName() <- MVC approach to get view from config


Tim Toady
13 Sep 2012, 10:30 AM
Ext.widget is not a getter. It creates and returns component based on a config rather than the way Ext.create does it.

Ext.getCmp should be avoided as it requires the use of static IDs on a component.

getComponent is fine if you have a reference to the parent of the item you want and know the childs itemId.

this.get____ I am assuming you are referring to using refs (http://docs.sencha.com/ext-js/4-1/#!/api/Ext.app.Controller-cfg-refs)to create getters for components. This is generally my preferred way. I find it clean and it also only does the work to find it the first time.

I will occassionaly use down (http://docs.sencha.com/ext-js/4-1/#!/api/Ext.container.AbstractContainer-method-down) and up (http://docs.sencha.com/ext-js/4-1/#!/api/Ext.AbstractComponent-method-up) as well when a ref might be a little overkill.

If you wanted to get more than one component with your component query you would want to do something like Ext.ComponentQuery.query (http://docs.sencha.com/ext-js/4-1/#!/api/Ext.ComponentQuery-method-query) rather than down/up/refs

Sorry for the double answer, I took too long to type that I guess and was beat by a solid 8 minutes.

13 Sep 2012, 10:37 AM
I guess and was beat by a solid 8 minutes

I started running before the shot was fired ;)