You need to sign in to do that
Don't have an account?
abhik 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");
action.setCallback(this,function(response){
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)));
component.set("v.expenses",response.getReturnValue());
}else{
console.log(state);
}
});
$A.enqueueAction(action);
}
})
Apex:code
public class ExpensesController {
@AuraEnabled
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 ??
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");
action.setCallback(this,function(response){
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)));
component.set("v.expenses",response.getReturnValue());
}else{
console.log(state);
}
});
$A.enqueueAction(action);
}
})
Apex:code
public class ExpensesController {
@AuraEnabled
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 ??
https://salesforce.stackexchange.com/questions/170095/lightning-components-basics-connect-to-salesforce-with-server-side-controllers