[SalesForce] Passing parameter from component to javascript controller

I have been looking for a way to pass a parameter from a Lightning component's aura:iteration to a javascript controller. I have searched for a solution but have not been able to find one for Aura, only for Visualforce. Surely the authors of Aura have considered something as basic as passing parameters from html, so what am I missing? The code below is what I would expect to work, but doesn't. Thanks for your help.

Inside my component

<aura:attribute name="monkeys" type="List" />

<aura:iteration items="{!v.monkeys}" var="monkey">
    <span onclick="{!c.getMonkeyLove({!monkey.love})}">{!monkey.love}</span>
</aura:iteration>

Inside my controller

getMonkeyLove : function (component, event, helper, data) {
    console.log(data); //Bananas
}

Best Answer

You can add data-* attributes to span like this:

 <span data-love="{!monkey.love}" onclick="{!c.getMonkeyLove}">{!monkey.love}</span>

In controller:

  getMonkeyLove: function(cmp,event,helper){
    var monkeyLove = event.getSource().getElement().getAttribute('data-love');
  }
Related Topic