function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
d.tejdeep@nicomatic.ind.tejdeep@nicomatic.in 

How to pass map value via action to apex controller from lightning component ?

action.setParams({
                "Bt": component.get("v.BatchList"),
                "QliRowNum": 1,
                "RowIndex":[component.get("v.rowIndex"),component.get("v.BatchList")]
            });
            action.setCallback(this,function(resp){
lightning APEX: 
@AuraEnabled
    public static list<batch__c> SaveBatchDet(integer QliRowNum,list<Batch__c> Bt,map<string,list<batch__c>> RowIndex){

I want to pass  MAP value 

"RowIndex":[component.get("v.rowIndex"),component.get("v.BatchList")]

How can i do that ?
 
Rashmi Kumari 33Rashmi Kumari 33
So, component markup:

<aura:component controller="Your_Controller">
    <aura:attribute name="theMap" type="Map" default="{}"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
</aura:component>
Controller code:

({
    doInit : function(component, event, helper) {
        var action = component.get("c.SaveBatchDet");
        var theMap = component.get("v.theMap");
        //add some params
        theMap["key1"]="test1,test2,test6";
        theMap["key2"]="test3,test4,test5";
        action.setParams({
           "RowIndex": theMap
        });
        action.setCallback(this, function(result) {} );
        $A.enqueueAction(action);
    }
})

Apex :

@AuraEnabled
public static list<batch__c> SaveBatchDet(map<string,list<batch__c>> RowIndex){
         system.debug('RowIndex'+RowIndex);
}
Suraj Tripathi 47Suraj Tripathi 47

Hi  d.tejdeep@nicomatic.in 
If you want to pass the map from helper to apex then you have to create a map attribute and you have to store all values in the map and you have passed in the Setparms in action. And In the apex method, you have passed a variable that must be Map type.


If you resolved your bug. Please mark my Best answer.
 
Thanks 
Suraj Tripathi