EXTJS4 Study (iv): The difference between ID and itemid in ExtJS

Source: Internet
Author: User

to make it easier to represent or specify the name of a component, we typically use an ID or Itemid for the identity designation. (It is recommended to use Itemid as much as possible to reduce conflicts resulting from unique page identifiers)
Id:
The ID is a unique identifier for the component of the entire page, which also means that only the ID of a unique name is allowed throughout the page, and the ID of the component here will also be the ID in element, so if there are two, The page will be collapsed deformation and so on can not imagine problems.
And as a component must have its own unique identifier (ID), the system will automatically add an ID to the component without setting the ID of the component

ItemId:
Itemid is used for components underneath the container, which also means that Itemid is only a local component identification name, which is not required to be unique globally. from the above narrative can be seen some of the use of the need to pay attention to the place
  1. If you want to get the relevant component if it belongs to container please set the ID

  2. If you only belong to a component under a container, set the Itemid; In some cases you can also set it together with the ID, such as the need to change the CSS style, in addition to Itmeid or preferred choice

  3. GETCMP and getcomponent are not the same, use must be noted, must be paired with the ID and Itemid use

As a result, the ID and Itemid will have a dependency, it is unnecessary to define the ID, and will not cause the ID to be used to avoid repeated, and because Itemid is under an ID, so even if Itemid repeat, you can take advantage of the unique ID ext.getcmp After obtaining the reference, use Getcomponent to obtain the reference of the owning Itemid.


How to get IDs and Itemid components and components ( from the above can be seen clearly, Itemid is a partial component name

ID: EXT.GETCMP (ID);

itemId: EXT.GETCMP (ID). getcomponent (ItemId);


Look at the code again.

var c = new Ext.panel.Panel ({     height:300,    renderTo:document.body,    layout: ' Auto ',    items: [        {            ItemId: ' P1 ',            title: ' Panel 1 ',            height:150        },        {            itemId: ' P2 ',            title: ' Panel 2 ',            height:150        }    ]}) p1 = C.getcomponent (' p1 '); P1 = C.child (' #p1 '); P2 = p1.ownerCt.getComponent (' p2 ');p 2 = p1.ownerCt.child (' p2 ');

The Itemid in P1,P2 is replaced by an ID, which is obtained by P1 = C.child (' #p1 '); Also can be obtained, but certainly not suitable,

As you can imagine, if you create a C again, the ID repeats.

We can simply understand that the ID is a global variable, itemid is a local variable

EXTJS4 Study (iv): The difference between ID and itemid in ExtJS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.