I'm now learning Lightning and trying to build some simple app.

I followed this answer to get navigation between views. And in my component(foo) I got the following:

<aura:attribute name="myObjects" type="ak90.myObject__c[]"/>
<aura:attribute name="objId" type="String" />
//some code ...
<aura:iteration items="{!v.myObjects}" var="obj">
        <ui:button label="{!obj.ak90__Name__c}" aura:id="{!obj.Id}" press="{!c.navToBar}"/>

And depending on which button was clicked I want to set objId attribute to Id of that record so that I can pass it to the next view that should load more detailed view of that record.

2 Answers 2


I feel like there should be a better solution, but one way to achieve what you're trying to do is to create a separate component to put inside your aura:iteration.

So, let's say you edit your aura:iteration to look like this:

<aura:iteration items="{!v.myObjects}" var="obj">
    <ak90:objectListItem item="{!obj}"/>

And you create an objectListItem component that looks like this:

<!-- Attribute definition(s) -->
<aura:attribute name="item" type="ak90.myObject__c"/>

<!-- UI element(s) -->
    <ui:button label="{!item.ak90__Name__c}" aura:id="{!item.Id}" press="{!c.navToBar}"/>

In your c.navToBar() function, you'll be able to use component.get("v.item.Id") to figure out which specific button was pressed. From there, you can fire an event that includes the specific Salesforce ID corresponding to the pressed button, and then do what you need from there.

  • thanks for the answer! Actually I did the exact same thing this afternoon :)
    – Novarg
    Mar 12, 2015 at 22:00

Apparently there is an easier way - as explained in this trailhead

<button onclick="{!c.onclick}" data-data="{!v.data}" />Edit</button>

You can pass data to button event using data-data attribute and you get that data from the event parameters in the handler.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .