0

I am trying to pass an attribute from parent component to child component. But the catch is this attribute is populated in apex controller using wrapper class. So currently it is a list of wrapper object. But when I am trying to pass this attribute to child component, on console log of child client controller it is showing undefined.

Parent Apex Class:

public static List<dataWrapper> getParentDetails(String RecordId){
        list<dataWrapper> lstwrpParent = new List<dataWrapper>();
//doing some query and adding to the list
return lstwrpParent 
}

public class dataWrapper{
        @auraEnabled
        public Id childRecordId{get;set;}
        @auraEnabled
        public String childName{get;set;}
        @auraEnabled
        public String recordTypeName{get;set;}
        
        public dataWrapper(Id childRecordId,String childName,String recordTypeName){
            this.childRecordId=childRecordId;
            this.childName=childName;
            this.recordTypeName=recordTypeName;
        }
    }

Parent Controller:

// setting the lstwrpParent response from apex class to v.parentrecordlist

Parent Component:

<aura:attribute name="parentrecordlist" type="Object"/>
<lightning:card title="">
      <c:ChildComponent parentData="{!parentrecordlist}" />
    </lightning:card>

Child Component:

<aura:attribute name="parentData" type="Object"/>

Child js Controller:

var test1= component.get("v.parentData");
console.log("parentData "+ test1 );
0

make sure check in Server call response your getting the response or not there, and then like on Success of your server call add this line before assigning to "parentrecordlist" variable.

if(state === "SUCCESS"){
 console.log('data:',response.getReturnValue());// check if here data coming
 component.set("v.parentrecordlist",response.getReturnValue());
}

then Change the attribute from type:

<aura:attribute name="parentData" type="Object"/>

To

<aura:attribute name="parentData" type="yourclassName.dataWrapper[]" />
8
  • yes, server call is returning values. checked using console.log("parent " + JSON.stringify(response.getReturnValue())); Even replacing type to list is showing undefined in child js controller console log
    – Akash
    Dec 17 '20 at 5:28
  • we are good there, did you try changing the attribute type?
    – Umesh Beti
    Dec 17 '20 at 5:30
  • yes changed the attribute type to list from object still undefined.
    – Akash
    Dec 17 '20 at 5:31
  • i have updated my answer check now!
    – Umesh Beti
    Dec 17 '20 at 5:34
  • tried your yourclassName.dataWrapper[] approach but still undefined. made changes in both parent and child component aura attribute type
    – Akash
    Dec 17 '20 at 5:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.