Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExtJs 4, is there a way to find control? (not by "id")

I have button with id = 'someid', i can find it by Ext.getCmp('someid')...

Is there a way to set some kind of "extraId" to that button, and find that button by "extraId'?

like image 869
obenjiro Avatar asked Nov 29 '22 03:11

obenjiro


2 Answers

The question is where you want to search to get your item.

Another way could be the itemId.

An itemId can be used as an alternative way to get a reference to a component when no object reference is available. Instead of using an id with Ext.getCmp, use itemId with Ext.container.Container.getComponent which will retrieve itemId's or id's. Since itemId's are an index to the container's internal MixedCollection, the itemId is scoped locally to the container -- avoiding potential conflicts with Ext.ComponentManager which requires a unique id.

Source and further documentation: http://docs.sencha.com/ext-js/4-0/#/api/Ext.AbstractComponent-cfg-itemId

The ComponentQuery (mentioned by wombleton) is also a good way but maybe not as performant as the itemId.

like image 199
SimonSimCity Avatar answered Dec 07 '22 23:12

SimonSimCity


You can search for it by doing an Ext.ComponentQuery.

Example that will work in the console on the linked page:

Ext.ComponentQuery.query('button[text=OK]')

You can replace text=OK with the attribute you are searching for.

like image 22
wombleton Avatar answered Dec 08 '22 00:12

wombleton