Play Games

Search This Blog

Tuesday, August 25, 2020

How to display index of an element in a list in aura component - Salesforce Globe For You

 How to display index of an element in a list in aura component  - Salesforce Globe For You 

Solution:Use indexVar attribute of aura:iteration to display index of an element

Example:

IndexOfElement.cmp

<aura:component >

    <aura:attribute name="CricketPlayers" type="List" default="['Sachin','Kohli','Dhoni','Rohit']"/>

    The Cricket Players are <br/>

    <aura:iteration items="{!v.CricketPlayers}" var="player" indexVar="index">

        {!index+1}) {!player}<br/>

    </aura:iteration>

</aura:component>

TestApp.app

<aura:application extends="force:slds">

<c:IndexOfElement/>

</aura:application>

Output:


No comments:

Post a Comment