I am unable to pass parameter from the lightning controller to the apex class. Whenever I use debug the passed value seems null.
JavaScript Controller
add : function(cmp,event,helper) {
event.target.parentNode.style.display = 'none';
document.getElementById("cartdiv").style.display = 'block';
var selectedAccount =event.target.id;
var act = cmp.get("c.Cartveg");
act.setParams({"s":selectedAccount});
act.setParams({"cartlist" : cmp.get("v.cart")});
act.setCallback(this,function(a){
cmp.set("v.cartitem",a.getReturnValue());
});
$A.enqueueAction(act);
cmp.set("v.whichButton", selectedAccount);
}
Apex Class
@AuraEnabled
public static List<Vegetable__c> Cartveg(string s,List<Vegetable__c> cartlist)
{ system.debug(s);
List<Vegetable__c> clist= [SELECT Id, Name , Price__c , img__c
FROM Vegetable__c where Name =:s];
clist.addAll(cartlist);
system.debug(clist);
return clist;
}
Value of s is null. Please help
Best Answer
In lightning you need to set param
setParams
accept the multiple values so you need to passyou need to pass both
s
andcartlist
in single paramscomplete code