doInit : function(component, event, helper) {
helper.method1(component);
helper.method2(component);
helper.method3(component);
}
Need to call these helper methods in lightning client side controller synchronously.
Component markup:
Here's my code:
<aura:component controller="EmpAttachmentListController">
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<aura:attribute name="empList1" type="Employee__c[]" />
<aura:attribute name="empList2" type="Employee__c[]" />
<table>
<tr>
<th>Employee Name</th>
<th>Imgs Count</th>
</tr>
<aura:iteration indexVar="index" var="emp" items="{!v.empList1}">
<tr>
<td>{!emp.Employee_Name__c}</td>
<td>
{!emp.Attachments.length} Imgs <a href="#" onclick="{!c.toggleRecord}" id="{!index}">show/hide</a>
</td>
</tr>
<tr>
<td>
<p id="{!'index'+index}" class="showP">
<aura:iteration var="attach" items="{!emp.Attachments}">
<img src="{!'/servlet/servlet.FileDownload?file='+attach.Id}" />
</aura:iteration>
</p>
</td>
</tr>
</aura:iteration>
</table>
</aura:component>
controller.js
({ doInit : function(component, event, helper)
{
helper.getEmpList(component);
}
});
helper.js
({
getEmpList: function(component) {
var that = this;
var action = component.get("c.getEmpList");
action.setCallback(that, function(result) {
component.set("v.empList", result.getReturnValue());
that.getEmpList2(component);
});
$A.enqueueAction(action);
},
getEmpList2: function(component) {
var that = this;
var action = component.get("c.getEmpList2");
action.setCallback(that, function(result) {
var c = component.find("index0"); ** //Getting undefined error here **
component.set("v.empList2", result.getReturnValue());
});
$A.enqueueAction(action);
}
})