I built an application with Lightning Experience. In my custom apex controller, I have a method named getParam
.
public class compController {
@AuraEnabled
public static List<ObjectParent> getParam (Id master) {
List<ObjectParent__c> objList = [SELECT ID, Name, (SELECT ID, textField1__c, checkBox1__c FROM Child__r] FROM ObjectParent WHERE MasterID__c =: master];
return objList;
}
}
Lightning Component
<aura:component>
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<aura:attribute name="listObjectParent" type="ObjectParent" />
<aura:attribute name="master" type="String" default="1231242112341" />
<aura:iteration items="{!v.listObjectParent}" var="objdata"
indexVar="index">
<p>{!objdata.checkBox1__c}</p>
<p>{!objdata.textField1__c}</p>
</aura:iteration>
</aura:component>
JS Client Side Controller
doInit : function(component, event, helper) {
var action = component.get("c.getParam");
var master = component.get("v.master");
action.setParams({"master" : master});
action.setCallback(this, function(response){
var state = response.getState();
if(component.isValid() && state === "SUCCESS"){
var listObjectParent = response.getReturnValue();
component.set("v.listObjectParent", listObjectParent);
}else{
console.log("Failed with state: " + state);
}
});
$A.enqueueAction(action);
}
I need to initialize this with js client side controller at the component. I understand the output is a list in the list, which looks like:
- parent ID, parent name,
["ID","1234" ,"textField1__c", "xx1", "checkBox1", "true"]
- parent ID, parent name,
["ID","3456" ,"textField1__c", "xx2", "checkBox1", "false"]
Best Answer
The issue here is that you are getting value from Apex is a list and you are using an object attribute instead of list object:
Should be: