2

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;
}

2 Answers 2

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>

3
  • Thanks! I tried this already but it doesn't display field values.
    – Priya
    May 27, 2019 at 7:27
  • Did you removed v. @Priya May 27, 2019 at 9:02
  • yes I removed the v. and tried with just var in iteration tag.
    – Priya
    May 27, 2019 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>
3
  • It still doesnt display values. As li again is wrapper class instance.
    – Priya
    May 27, 2019 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, 2019 at 7:15
  • yes thanks I din't notice that May 27, 2019 at 7:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .