3

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

1 Answer 1

4

In lightning you need to set param

setParams accept the multiple values so you need to pass

setParams({"s":selectedAccount, "cartlist" : cmp.get("v.cart")});

you need to pass both s and cartlist in single params

complete code

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, "cartlist" : cmp.get("v.cart")});
    act.setCallback(this,function(a){
        cmp.set("v.cartitem",a.getReturnValue());
    });       
    $A.enqueueAction(act);
    cmp.set("v.whichButton", selectedAccount);
}
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .