I have parent and child components. I have reasons to keep child component as separate. I am trying to get the selected record information when I click any of the buttons(child component). Not sure what could be equivalent to event.target.parentNode.
Parent Component
<aura:iteration items="{!v.SECompanies}" var="company">
<tr>
<td> ***calling child component*****
<c:Actions aura:id="actionCmp"/>
</td>
<td>{!company.companyId}</td>
<td>{!company.companyName}</td>
<td>{!company.ultimateParentName}</td>
<td>{!company.street1}</td>
<td>{!company.address}</td>
</tr>
</aura:iteration>
Child Component
<aura:component description="Actions">
<aura:attribute name="seCompanyID" type="String"/>
<aura:attribute name="seCompanyName" type="String"/>
<div class="slds-media__figure">
<button class="slds-button slds-button--icon" aria-haspopup="true">
<lightning:icon iconName="action:new_opportunity" class="slds-is-open" size="xx-small" title="Create new Opportunity" /> |
</button>
<button class="slds-button slds-button--icon" aria-haspopup="true" onclick="{!c.createSEComp}">
<lightning:icon aura:id="editSEComp" iconName="action:edit" class="slds-is-open" size="xx-small" title="Edit SECompany"/>
</button>
</div>
</aura:component>
Child controller
({
createSEComp : function(component, event, helper){
var temp1 = event.target.data; //how to get the selected record information here?
console.log("component find is" +temp1);
}
})
Best Answer
The comment by @Martin Lezer is the right answer, I post this so there is a complete answer with code:
On your parent component you should send the company object to each child component:
Parent Component
Now all company data would exist in the
company
attribute in your child component (just define the type same as in your parent).Child Component Markup
Child Component Controller
Now, For calling your parent, you need to:
Lightning Component Event: ParentEvent
On the child markup you need to register that event to be able to call it (also you name this registration
callParentEvent
to catch it in your helper and trigger it:<aura:registerEvent name="callParentEvent" type="c:ParentEvent" />
On the child helper you need to triger it whenever you want:
var event = component.getEvent('callParentEvent').fire();
On your parent markup you need to listen to this event and call a method in your controller when it is triggered:
<aura:handler name="callParentEvent" event="c:ParentEvent" action="{!c.handleEventFromChild}"/>
On your parent controller you need a method to handle the triggered event:
Parent Controller