1

How to use aura:iteration over a list of Wrapper class object in Lightning component 1st Aura iteration works well it prints axisNo and axisName correct. But nested iterate with nested wrapper class list doesn't work.

Code for Component:

<tbody>
    <aura:iteration items="{!v.AxisWrapperList}" var="acc" indexVar="sNo">
        <!-- Child Lightning Component -->      
        <table  class="slds-table slds-table_bordered slds-table_cell-buffer">
             <tbody>
                 <tr>
                     <td>{!acc.axisNo}</td>
                     <td>{!acc.axis.Name}</td>
                 </tr> 
                 <td>
                     <aura:iteration items="{!v.AxisWrapperList.OpliWraList}" var="opli">
                         <table >
                             <tbody>
                                 <tr>
                                     <td>Quantity:{!opli.quantity}</td>                               
                                 </tr>
                             </tbody>
                         </table>
                     </aura:iteration>
                 </td>
             </tbody>
         </table>
     </aura:iteration>
 </tbody>

Apex Controller Wrapper class code:

public Class AxisWrapper{
    @AuraEnabled
    public List<OppLIWrapper> OpliWraList{get;set;}
    @AuraEnabled
    public Axis__c axis{get;set;}
    @AuraEnabled
    public Integer axisNo{get;set;}

    public AxisWrapper(){
        OpliWraList = new List<OppLIWrapper>();
    }
}
public Class OppLIWrapper{
    @AuraEnabled
    public OpportunityLineItem oppli{get;set;}
    @AuraEnabled
    public integer opliNo{get;set;}
    @AuraEnabled
    public string pcdate{get;set;}
    @AuraEnabled
    public integer axNo{get;set;}
    @AuraEnabled
    public Decimal quantity{get;set;}
    @AuraEnabled
    public Decimal sellingPrice{get;set;}
    @AuraEnabled
    public String strWonLost {get;set;}
    @AuraEnabled
    public boolean showHideTable{get;set;}
    @AuraEnabled
    public boolean showReqFld{get;set;}

    public OppLIWrapper(){
        oppli = new OpportunityLineItem();
        strWonLost = Null;
        showHideTable = false;
        showReqFld = False;
}
1

Iterate over var(acc) as acc is one of account.

<aura:iteration items="{!v.AxisWrapperList}" var="acc" indexVar="sNo"> 
    <aura:iteration items="{!acc.OpliWraList}" var="li"> 
        {!li.opli} {!li.opliNo} 
    </aura:iteration> 
</aura:iteration>

| improve this answer | |
  • Thanks! I tried this already but it doesn't display field values. – Priya May 27 '19 at 7:27
  • Did you removed v. @Priya – nubie May 27 '19 at 9:02
  • yes I removed the v. and tried with just var in iteration tag. – Priya May 27 '19 at 10:03
1

To iterate over the OppLIWrapper you need to use the var name of the AxisWrapperList (acc here).

<aura:iteration items="{!v.AxisWrapperList}" var="acc" indexVar="sNo">
    <aura:iteration items="{!acc.OpliWraList}" var="li">
        {!li.opli}
        {!li.opliNo}
    </aura:iteration> 
</aura:iteration>
| improve this answer | |
  • It still doesnt display values. As li again is wrapper class instance. – Priya May 27 '19 at 6:41
  • 2
    you do not need v. to access the property: {!acc.OpliWraList} should work fine. Also keep up the good work! – Raul May 27 '19 at 7:15
  • yes thanks I din't notice that – nubie May 27 '19 at 7:16

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.