16 Jun 2011 6:16 AM #1
id vs itemId
id vs itemId
We are currently developing a new front-end for our application using Ext. The main layout will have a tab panel in the center of the viewport and may have another tab panel within each tab. Those subtabs will then have different options with submittable forms for example. I have been writing all my forms using itemId for all of my items and referencing them using the .down function. Another developer working on this project has been using id and putting a prefix in front of the id of every item based on the tab/subtab that the item is in and then referencing the item directly using the id. I understand that both of these approaches work and that technically neither is incorrect. However, I would like to get some feedback on which would be better to use for a large application and why. The API Docs all seem to hint towards using itemId over id so that unique ids are not accidentally repeated which would cause issues, but putting a prefix on each id based on the tab would solve that problem. What are the other reasons for using itemId over id? Also, is the time it takes to reference items using the itemId significantly slower than just referencing the item directly using the id, or is this not something to worry about?
8 Dec 2011 8:51 AM #2
22 Jan 2013 7:21 PM #3
I'd like to know this too, anyone and explain?
11 Dec 2013 2:58 AM #4
Item id vs id
Item id vs id
Just started working on Sencha. I have the same query!!
11 Dec 2013 4:39 AM #5
There's no performance difference between using id and itemId.
When you use an id for a component, there must be a single instance of this component, so it's recommended to avoid using ids.
itemId must be unique only within the component's immediate container.
3 Mar 2014 11:53 AM #6
Using id could lead to future bugs due to name collision, as the application grows, components get reused, development teams grows and people get reallocated. Your colleague's approach relies on tracking a list of already used prefixes / ids.
Sencha recommends to avoid using id on the AbstractComponent.id API and on the blog (item #6).
Other related links:
8 Mar 2014 5:57 PM #7
ItemId is unique and local to the container where id is unique globally.
If you know the container of the component you are looking for, then using getComponent(itemId) should be faster because it will traverse less items in its HashMap, it is only looking for direct child components.
If you do not know the container then you can use getCmp(). But if you are doing this a lot or in a loop, it would be better to get the container by getCmp() first, then get the child components by getComponent(itemId).
The components of an app are in a hierarchy. However if you only know a very top level component, to get to the bottom components may require multiple getComponent() calls or Ext.ComponentQuery calls, making the code complex. There is also a very nasty side-effect, if you rearrange any of the hierarchy you code will break. Rearranging a component hierarchy may happen when an app allows re-positioning of the components, or it may happen as a result of an application enhancement. So traversing using multiple getComponent calls or using Ext.componentQuery.query this way is not always a good idea. Using both getCmp and getComponent in a way that minimizes rigidity of the app is best.varsos