-1

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;   
    }
5
  • 1
    Your code has a ton of problems with it, so much I can barely guess its intent. You may want to start over, and try building a list all by itself as a starting point.
    – sfdcfox
    Commented Jan 22, 2018 at 22:14
  • I am actually trying to print the table with Cart, Quantity, Price. The Cart = Description, QT = Quantity__c and Price is named blank but APi is Price__c. I am able to get the contents printed in the console when the changed var getallitems = component.get("v.response")['ct']; to get the component values from controller. But I am unable to print on UI
    – user5432
    Commented Jan 22, 2018 at 22:24
  • 2
    Yeah, I'm not sure how you'd see anything from component.get("v.response") because you never set it anywhere. Your variable and attribute names are a mess.
    – sfdcfox
    Commented Jan 22, 2018 at 22:46
  • I just updated the code. My bad, I pasted the wrong code initially
    – user5432
    Commented Jan 22, 2018 at 22:56
  • 1
    v.List is undefined I'm pretty sure. Try creating a SSCCE (sscce.org). So that we can help you with your problem more easily, instead of you just dumping all your code here.
    – Aequitas
    Commented Jan 22, 2018 at 23:08

1 Answer 1

0

As sfdcfox mentioned, 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);
    }
})

You must log in to answer this question.

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