Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@dudunato dudunato commented Mar 25, 2017

This is still not working :/

@rsoesemann

This comment has been minimized.

Copy link

@rsoesemann rsoesemann commented May 31, 2017

Indeed!

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