You need to sign in to do that
Don't have an account?
JeffreyStevens
Lightning Component help - getting data from controller
After completing the trailhead for Lightning components, I'm trying one in my sandbox now. I'm missing something, and maybe it's my Attribute in the Component, but I'm not sure? My output doesn't produce the {!v.Transactions[0].name} field (just the "[Transactions List...]".
Component
Apex Controller
Component
<aura:component implements="forceCommunity:availableForAllPageTypes" access="global" controller="ctrl_TransactionList"> <aura:handler name="init" action="{!c.doInit}" value="{!this}" /> <div class="slds-page-header" role="banner"> <div class="slds-grid"> <div class="slds-col"> [Transactions List...]<br/> <ui:outputText value="{!v.Transactions[0].name}" /> </div> </div> </div> </aura:component>Componenet Controller
({ doInit: function(component, event, helper) { console.log('doInit...'); var action = component.get("c.getTransactions"); action.setCallback(this, function(response) { var state = response.getState(); if(component.isValid() && state === "SUCCESS") { component.set("v.items", response.getReturnValue()); } else { console.log("Failed with state: " + state); } }); $A.enqueueAction(action); }, })
Apex Controller
public without sharing class ctrl_TransactionList { @AuraEnabled public static list<Transaction__c> getTransactions() { return [SELECT id,name,Payee__r.Name FROM Transaction__c WHERE id = 'a0T2A00000LDUQf']; } }
Add this above your aura handler (On Line 2).
And in your client-controller code (on Line 11), you are setting yoour return value to "v.items" which doesn't exist in your component.
So, you need to fix it too.
All Answers
Add this above your aura handler (On Line 2).
And in your client-controller code (on Line 11), you are setting yoour return value to "v.items" which doesn't exist in your component.
So, you need to fix it too.
So, I changed the v.Items to v.Transactions also.
Thanks