+ Start a Discussion
abhik dey 1abhik dey 1 

Lightning Components Basics - Connect to Salesforce with Server-Side Controllers- Queries

Hi Everyone,

As part of these module, can you help me understanding the below logic

in order to display the expense from APEX, below is the logic used
    doinit : function(component, event, helper) {
        var action = component.get("c.getExpenses");
           var state = response.getState();
            if(component.isValid() && state == "SUCCESS"){ 
           //     var expview = component.get("v.expenses");
            //    expview.push(response.getReturnValue());
               // component.set("v.expenses",JSON.parse(JSON.stringify(expview)));


public class ExpensesController {

    public static List<Expense__c> getExpenses(){
        return [Select Id,Amount__c,Client__c,Date__c,Reimbursed__c,Name from Expense__c] ;       

Aura Attribute expenses is getting set with the controller response (component.set("v.expenses",response.getReturnValue());). But If I want to use the commented lines,  by doing a push and then set the component. It didn't work. WHy is that so ? I am doing a component get and then pushing the value which is the way even showed in the later section of this module while saving an expense record.

When to use the PUSH and when i can directly do a component.set?

can anyone help me in clarifying the doubts ??
Best Answer chosen by abhik dey 1
abhik dey 1abhik dey 1
got  quick response from stack exchange forum.