you could do this in two ways:
1.you could do set the data-index
instead of id
to hold the index in the component and access the clicked value using the id's value in the controller:(based on CharlesT comment)
<aura:iteration var="pf" items="{!v.family}" indexVar="ind">
<li class="slds-dropdown__item">
<a data-index="{!ind}" href="javascript:void(0);" role="menuitemradio" onclick="{!c.prodShow}">
<p class="slds-truncate">
<c:svg ariaHidden="true" class="slds-icon slds-icon--selected slds-icon--x-small slds-icon-text-default slds-m-right--x-small" xlinkHref="/resource/SLDS102/assets/icons/utility-sprite/svg/symbols.svg#check"/>
{!pf}</p>
</a>
</li>
</aura:iteration>
In the controller.js
({
prodShow: function(cmp, ev) {
var index = event.target.dataset.index;
console.log(cmp.get("v.family")[index]);
}
})
2.you need to break the component into two : Event Driven Way
For instance,
1.ListCmp - (fetches the data) -> Parent Component
2.ListItemCmp - (displays each record) -> Child component
And use the Event driven way to pass the clicked record from the ListItemCmp to the ListCmp.
ListCmp.cmp
<aura:component>
<aura:attribute name="family" type="Object[]"/>
<aura:handler name="sendRecordToParent" event="c:selectedRecordEvt" action="{!c.gotRecordFromChild}" />
<aura:iteration var="pf" items="{!v.family}" indexVar="ind">
<c:ListItemCmp item="{!pf}" />
</aura:iteration>
</aura:component>
ListCmpController.js
({
editRecord : function(cmp, ev) {
var selectedValue = event.getParam("record");
console.log(selectedValue);
}
})
This is an Component level event you should create, which carries the data to the parent.
selectedRecordEvt.evt
<aura:event type="COMPONENT">
<aura:attribute name="record" type="String"/>
</aura:event>
ListItemCmp.cmp
<aura:compoent>
<aura:attribute name="item" type="String"/>
<aura:registerEvent name="sendRecordToParent" type="c:selectedRecordEvt"/>
<li class="slds-dropdown__item">
<a href="javascript:void(0);" role="menuitemradio" onclick="{!c.sendToParent}">
<p class="slds-truncate">
<c:svg ariaHidden="true" class="slds-icon slds-icon--selected slds-icon--x-small slds-icon-text-default slds-m-right--x-small" xlinkHref="/resource/SLDS102/assets/icons/utility-sprite/svg/symbols.svg#check"/>
{!v.item}</p>
</a>
</li>
</aura:component>
ListItemCmpController.js
({
sendToParent : function(component, event, helper) {
var event = component.getEvent("sendRecordToParent");
event.setParams({
'record':component.get("v.item")
});
event.fire();
})
Also, the OP's solution :
var prodFam = event.currentTarget.childNodes[0].innerText;
would also work if the element exist in the same namespace in the component.