Skip to content

Instantly share code, notes, and snippets.

Created January 12, 2017 00:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/fcf2e7aee13d3d9f8cc2e125c5c9174b to your computer and use it in GitHub Desktop.
Save anonymous/fcf2e7aee13d3d9f8cc2e125c5c9174b to your computer and use it in GitHub Desktop.
How to get the event target?
<aura:component>
<aura:attribute name="data" type="List"/>
<aura:handler name="init" action="{!c.initHandler}" value="{!this}"/>
<aura:iteration items="{!v.data}" var="dataRow">
<li>
<a onclick="{!c.iterationHandler}" data-object="{!dataRow.stringified}">Item {!dataRow.Name}</a>
</li>
</aura:iteration>
</aura:component>
({
initHandler: function(cmp) {
var data = [
{'stringified': '{}', 'Name': 'Red Sox'},
{'stringified': 'true', 'Name': 'White Sox'},
{'stringified': '"foo"', 'Name': 'Giants'},
{'stringified': '[1, 5, "false"]', 'Name': 'Yankees'}
];
cmp.set('v.data', data);
},
iterationHandler: function(cmp, event) {
var valueObject = JSON.parse(event.target.getAttribute('data-object'));
console.log(valueObject);
}
})
@dudunato
Copy link

This is still not working :/

@rsoesemann
Copy link

Indeed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment