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
34213421 

lightning aura iteration returning blank rows

I am having fits with lightning aura iteration, it doesn't do anything just puts in a blank row, no errors .Having zero luck here is my lightning component
Component:
 
<table class="slds-table slds-table--bordered slds-table--cell-buffer">

                            <tr class="slds-text-title--caps">
                            <th scope ="col">
                                <div class="slds-truncate" title="Cart">Cart</div>
                            </th>
                            <th scope="col">
                                <div class="slds-truncate" title="QT">QT</div>
                            </th>
                            <th scope="col">
                                <div class="slds-truncate" title=""></div>
                            </th>
                        </tr>

                    <tbody>
                            <aura:iteration items="{!v.orderItemList}" var="ct">

                                    <tr>
                                <th scope="row" data-label="Cart">
                                    <div class="slds-truncate" title="{!ct.Description__c}">{!ct.Description__c }</div>
                                </th>
                                <td data-label="QTY">
                                    <div class="slds-truncate" title="{!ct.Quantity__c}">{!ct.Quantity__c}</div>
                                </td>
                                <td data-label="">
                                    <div class="slds-truncate" title="{!ct.Price__c}">{!ct.Price__c}</div>
                                </td>
                            </tr>  
                        </aura:iteration>
                    </tbody>
                        </table>
Here is the JS:
 
({
    doInit : function(component, event, helper) {
        var action = component.get("c.getOrder");
        action.setParams({
            "recordId":component.get("v.recordId")
            //"recordId":"8010K0000026d6Y"

        });

        action.setCallback(this,function(response){

            var state = response.getState();
            if(state === "SUCCESS"){
               component.set("v.order",response.getReturnValue()); 
               console.log(response.getReturnValue());

            }
        });

        $A.enqueueAction(action);

    },

    sendE : function(component, event, helper) {

        var email = component.get("v.order.Email__c");
        var subject = component.get("v.order.Subject__c");
        var action2 = component.get("c.sendEmail");
        var getallitems = component.get("c.orderItem")['ct'];
        var ItemList =[];

        for (var key in getallitems){
           ItemList.push(key+ '=' +getallitems[key]); 
        }
        component.set("v.ItemList", orderItemList);
        console.log(orderItemList);
        action2.setParams({

            "email":email,
            "rId":component.get("v.recordId"),
            "subject":subject

        });
        action2.setCallback(this,function(res){

            var state = res.getState();
            if(state === "SUCCESS"){
                alert("win");
               //component.set("v.order",response.getReturnValue()); 
               console.log(res.getReturnValue());

            }
            else{

                console.log("failed");
            }
        });
        $A.enqueueAction(action2);

    }


})
Controller:
 
public  static Line__c orderItem {get;set;}
     @AuraEnabled
    public static Line__c getOrderLines(string recordId) {
     orderItem = [select Id,Quantity__c,Price__c,Price__c,
                 Description__c,Order__r.Total__c
                 from Line__c where Order__c=:recordId];
        system.debug('Order rows'+orderItem);
        return orderItem;   
    }



 
NagendraNagendra (Salesforce Developers) 
Hi,

May I suggest you check your variable names;

You have component.set("v.ItemList", orderItemList); but your variable you are iterating is called <aura:iteration items="{!v.orderItemList}" var="ct"> are these ItemList and orderItemList meant to be the same?

I have created a basic example for you:

Lightning Component:
<aura:attribute name="stringArray" type="String[]" default="a,b" />
<aura:handler name="init" value="{!this}" action="{!c.init}"/>

<aura:iteration items="{!v.stringArray}" var="ct">
    {!ct}
    <br/>
</aura:iteration>
Javascript controller:
({
    init : function(component, event, helper) {
        let stringArray = component.get("v.stringArray");
        stringArray.push('c');
        component.set("v.stringArray", stringArray);
    }
})
Thanks,
Nagendra

 
34213421
I did try that code and I am receiving an error which says Invalid attribute "name": Source when I try saving the component. I did modify the code to have only the orderItemList everywhere in place of string Array