I'm creating and displaying lightning buttons in aura components dynamically. On click of each button, I'm trying to fetch its index using event.target.getAttribute. I'm able to get it but sporadically. Below is the code.
<div class="slds-grid slds-gutters product-btn">
<aura:iteration items = "{!v.buttonList}" var = "btn" indexVar = "index" >
<div class="slds-col" data-row-index = "{!index}">
<lightning:button onclick="{!c.callJSController}" label="{!btn.key}"/>
</div>
</aura:iteration>
</div>
callJSController : function(cmp, event, helper) {
let index = event.target.getAttribute("data-row-index"); //becomes null sometimes
}
Can anyone help me out what am I missing here or is there any other way to handle it efficiently.