Lightning: Component IDs

Lightning: Component IDs

two types of IDs: a local ID and a global ID

Local IDs
1. scoped to the component
2. often unique but it's not required to be unique
3. Create a local ID by using the aura:id attribute
4. aura:id doesn't support expressions. You can only assign literal string values to aura:id.
ex: <lightning:button aura:id="button1" label="button1"/>
5. Find the button component by calling cmp.find("button1")
6. If the local ID is unique, find() returns the component.
7. If there are multiple components with the same local ID, find() returns an array of the components.
8. If there is no matching local ID, find() returns undefined.
Global IDs
1. component has a unique globalId
2. generated runtime-unique ID of the component instance
3. not guaranteed to be the same beyond the lifetime of a components
4. for debugging purposes
5. use the globalId as a prefix or suffix for your element
ex: <div id="{!globalId + '_footer'}"></div>
6. retrieve a component's global ID in JavaScript, using the getGlobalId() function.
ex: var globalId = cmp.getGlobalId();

Rajendar Bommidi
Salesforce Certified Platform Developer I and App Builder, Tech Mahindra

No comments:

Powered by Blogger.