function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Thirumagal SiluvaithasanThirumagal Siluvaithasan 

Access the list in wrapper class to LWC

Hi Team,

I have a wrapper class in my apex controller.
 
global class variableDTO {
        @AuraEnabled
        public String bkImgURL { get; set; }
        @AuraEnabled
        public List<String> monthListBefore {get; set;}
}

And I am trying to to access the monthListBefore list in LWC. My code is below.
 
@track background; 
@track MonthList;

@wire(getAllDTOs) wrappers ({
        error,
        data
    }) {
        if(data) {
            this.objects = data;
            this.background = data[0].bkImgURL;
            this.MonthList = data[0].MonthListBefore;
            console.log(this.background );
            console.log(this.MonthList );
        

        } else {
            this.error = error;
        }
    }
Here I got value for this.background but I got undefined for this.MonthList. Is there anything wrong in my code?

I got value MonthListBefore in json when I debug.
"monthListBefore":[ 
"Avr",
"Mai",
"Jui",
"Jui",
"Aoû",
"Sep",
"Oct",
"Nov",
"Déc"
],

Thank you.

 
karthikeyan perumalkarthikeyan perumal
Hello, 

Change your track like below, 
 
@track MonthList= {};
MonthList is declared by initialising to null. So even before wired function gets back the data, the template is trying to display data[0].MonthList which is throwing error.

hope this will help you. 

Thanks
karthik
 
Thirumagal SiluvaithasanThirumagal Siluvaithasan
@karthikeyan perumal
Here the issue was I am using "monthListBefore" in controller But in javascript I am using "MonthListBefore".Both are different. Its case sensitive.
Thank You for your help!
Manisha Rani 18Manisha Rani 18
@Thirumagal Siluvaithasan .. Could ypu please share the code for apex controller in which you are getting the array values in "monthListBefore"!
Suraj Tripathi 47Suraj Tripathi 47
Hi Stacey ,

 Replace your code by this @track place.
 
@track MonthList= {};
If you find your Solution then mark this as the best answer.

 

  Thank you!


  Regards,
  Suraj Tripathi