You need to sign in to do that
Don't have an account?
Praveen Mehar
i am getting an error => Cannot read property 'setCallback' of undefined,Please help.
Params1:
public class params1 {
@AuraEnabled
public static List<Account> accountthod(){
List<Account> accounts=[select id,name,industry,rating,phone from Account limit 4];
return accounts;
}
}
pasasm.cmp
<aura:component controller="params1">
<aura:attribute name="acclist" type="List"/>
<aura:handler name="init" value="{!this}" action="{!c.invoke}"/>
<aura:iteration items="{!v.acclist}" var="a">
<p>{!a.name} {!a.industry} {!a.rating} {!a.phone}</p>
</aura:iteration>
</aura:component>
parasmController.js
({
invoke : function(component, event, helper) {
var action=component.get("v.accountthod");
action.setCallback(this,function(response){
console.log("invoked");
var state=response.getState();
if(state==='SUCCESS'){
console.log('Operation successfull');
component.set("v.acclist",response.getReturnValue());
}else{
console.log('Operation failed');
}
});
$A.enqueueAction(action);
}
})
parasmap.app
<aura:application extends="force:slds">
<c:parasm />
</aura:application>
public class params1 {
@AuraEnabled
public static List<Account> accountthod(){
List<Account> accounts=[select id,name,industry,rating,phone from Account limit 4];
return accounts;
}
}
pasasm.cmp
<aura:component controller="params1">
<aura:attribute name="acclist" type="List"/>
<aura:handler name="init" value="{!this}" action="{!c.invoke}"/>
<aura:iteration items="{!v.acclist}" var="a">
<p>{!a.name} {!a.industry} {!a.rating} {!a.phone}</p>
</aura:iteration>
</aura:component>
parasmController.js
({
invoke : function(component, event, helper) {
var action=component.get("v.accountthod");
action.setCallback(this,function(response){
console.log("invoked");
var state=response.getState();
if(state==='SUCCESS'){
console.log('Operation successfull');
component.set("v.acclist",response.getReturnValue());
}else{
console.log('Operation failed');
}
});
$A.enqueueAction(action);
}
})
parasmap.app
<aura:application extends="force:slds">
<c:parasm />
</aura:application>
You have to use c.MethodName in below line not v.Methodname:
var action=component.get("v.accountthod"); ==> var action=component.get("c.accountthod");
Updated JS:
Updated Component : ( use the caps in starting letter of field name to refer the field values like below):
name ==> Name , industry ==> Industry, rating ==>Rating, phone ==> Phone
Thanks,
Maharajan.C
All Answers
You have to use c.MethodName in below line not v.Methodname:
var action=component.get("v.accountthod"); ==> var action=component.get("c.accountthod");
Updated JS:
Updated Component : ( use the caps in starting letter of field name to refer the field values like below):
name ==> Name , industry ==> Industry, rating ==>Rating, phone ==> Phone
Thanks,
Maharajan.C
<c:pasasm />
</aura:application>
Hi Maharajan,
Thanks for the resply, now its working fine.