Onclick of button through iteration shows index

test_a.app

<aura:application extends="force:slds">
   <ul>
        <aura:iteration items="[a1,a2,a3,a4]" var="product" indexVar="index">
            <li onclick="{!c.ShowDataOnClick}" data-row-index="{!index}">
                <p>{!product}</p>
             
            </li>
        </aura:iteration>
    </ul>
</aura:application>



({
        ShowDataOnClick: function(component, event, helper) {
           var index = event.currentTarget.dataset.rowIndex;
            console.log(index);
            console.log(event.currentTarget.dataset.rowIndex);
        }
    })

O/p

  • [a1
  • a2
  • a3
  • a4]

onclick a1--- 0
a2--- 1

Comments

Popular posts from this blog

Lightning Grid Custom Datatable

Comparing Two Values Using Aura If

Dynamic Standard Datatable Using Fieldset