Last active
June 16, 2017 08:04
-
-
Save ChristianMenzinger/616a9a85b37d9a0070c24b59ea6612b5 to your computer and use it in GitHub Desktop.
Example code related to StackExchange https://salesforce.stackexchange.com/questions/178487/event-propagation-breaks-with-api-v40-fundexplorer-demo-app/179130#179130
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<aura:application extends="force:slds"> | |
<aura:attribute name="listData" type="String[]" default="['First', 'Second', 'Third']" /> | |
<!-- HERE comes what is propoesed by performance best practices: only one click-event listener on the outer list --> | |
<ul onclick="{!c.onListClick}"> | |
<aura:iteration items="{!v.listData}" var="data" indexVar="index"> | |
<li data-itemindex="{!index}"> | |
<lightning:icon iconName="utility:chat" size="medium" title="title" /> | |
Data: {!data} | |
</li> | |
</aura:iteration> | |
</ul> | |
</aura:application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
({ | |
onListClick: function(component, event, helper) { | |
if (event.target === event.currentTarget) return; | |
//as I only have on event listener I have to step through the containment hierarchy | |
//to get the li-node where my data tag lives I am interested to | |
var el = event.target; | |
while (el && (!el.dataset || !el.dataset.itemindex)) { | |
el = el.parentElement; | |
} | |
if (el) { | |
console.log("Clicked item has index " + el.dataset.itemindex); | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NOTE that with API v39 this code works as expected, with API v40 it only works when clicking the text and does not when clicking the icon