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
Deepak agarwal 9Deepak agarwal 9 

Lightning actionResult.getReturnvalue

Hi All,
 
I am facing an issue in which i am getting lists of lists from Controller in lightning and want to set into array because i need each index of element from that list of lists.Here is the code.
Public static list<List<ZenObject__c>> getZenObjsOdd(){
          Integer colcount=getColumnsCount();
          Integer index=0,i;
          
      list<list<ZenObject__c>> lst=new list<list<ZenObject__c>>();
          List<ZenObject__c> ZenobjsOdd=new List<ZenObject__c>();
      List<ZenObject__c> Zenobjs=[Select ZenLms_Name_del__c,ZenLms_SubText__c,ZenImage__c from ZenObject__c order by createddate];
          integer listsize=Zenobjs.size();        
          for(integer col=1;col<=(listsize/colcount);col++){ 
              for(i=index;i<(index+colcount);i++){
                  ZenobjsOdd.add(Zenobjs[i]);    
              }  
              index=i;
               lst.add(ZenobjsOdd); 
          }
          if(math.mod(listsize,colcount)!=0)
          {
              for(integer j=index;j<index+(math.mod(listsize,colcount));j++){
                  ZenobjsOdd.add(Zenobjs[j]);
                  lst.add(ZenobjsOdd); 
                 
              }
          }
        return lst;  
      }

//JS controller
 getZenObjsOdd : function (component){
      var action = component.get("c.getZenObjsOdd"); 
 var items[];
      action.setCallback(this, function(actionResult){
        var state = actionResult.getState();
          if (component.isValid() && state === "SUCCESS"){ 
              items.push(JSON.stringify(actionResult.getReturnValue()));
              console.log('hihih ' +items);
             component.set("v.ZenObjsOdd",items);             
              } 
      });
         $A.enqueueAction(action);
},

From the code it is clear that i am pushing actionResult.getReturnValue()  in array.But there is something wrong here.Anyhelp would be appreciated,


Thanks,
Deepak.

JeffreyStevensJeffreyStevens
You might think about using a map of <String, list<sObject>> instead of a list<list<sobject>>.

However - I've done something close to this in lightning - and in that situation - I used a sub-class.  In my situation - I had a sub-class like this...
public class coursesAll{
		@AuraEnabled		public list<Course__c> 	scheduledCourses 	{get;set;}
		@AuraEnabled		public list<Course__c>  activeCourses 		{get;set;}
	}

That's what was returned.  

The .js controller was the same -  ( component.set("v.allCourses", response.getReturnValue());   )

The markup was like this...
<aura:iteration items="{!v.allCourses.activeCourses}" var="course">
 
Deepak agarwal 9Deepak agarwal 9
Thanks for reply.However i need to get values from map in js controllrer.I have actually worked around that idea chaning would again be a big mess for me.So if i got know that would be much better.