开发者

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 "extra开发者_运维问答Id" to that button, and find that button by "extraId'?


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.


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.


I don't have access to the ExtJS 4 API docs, but I know that in 3.X and previous verions have some other ways of getting references to your compoents without the use of the DOM ID.

If your components are part of a form or form panel, you should have access to a method called findField(). It is inherited from Basic Form. This method can take an id, dataIndex, name, or hiddenName to get a reference to your component.

There is also a helper method called findByType(xtype) that you can use to try and find your buttons. Another option would be to extend the button you use to place a unique property that you can use as a reference.


An alternative to id is itemId and it is limited to the scope of the container in which it is defined. So, in this case, there is not need to define globally unique itemId as done in case of id. We can use component query to get the component object having the itemId. Please follow this link where i have posted about how to use itemId and what is its benefit. http://jksnu.blogspot.in/2012/11/use-itemid-instead-of-id.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜