2

I want to add javascript map values to existing lightning map type variable

Map type in Component

<aura:attribute name="CheckedRecsMap" type="Map"  default="{}"/>

In js declaring a new map and adding the values and I want to add the map values to the existing component maps (CheckedRecsMap).

 var CheckedRecsMap = component.get("v.CheckedRecsMap");
 var newMap= new Map();
 newMap.set(index,RowItemList[index]);

 component.set("v.CheckedRecsMap", newMap); //Will replace the old values 

Basically, I want to push into Old map.

CheckedRecsMap.set and CheckedRecsMap.push throws the error.

2
  • have you looked at the new lightning map component? I did it on trailhead and it seems pretty good. lightning:map is the component. can be found developer.salesforce.com/docs/component-library/bundle/… Not sure if it will help but thought i would share Commented Mar 4, 2019 at 17:33
  • No, you misunderstood my question. I don't want lightning: map. I want to store key-value pair like apex Map
    – SFDC
    Commented Mar 5, 2019 at 12:43

1 Answer 1

3

You have to do this "manually":

newMap.forEach((value,key)=>CheckedRecsMap.set(value,key));

Or, you could use an Object instead, which works out more like this:

var CheckedRecsObj = component.get("v.CheckedRecsObj");
var newMap = { arg1: 'value1', arg2: 'value2' };
Object.assign(CheckedRecsObj, newMap);
1
  • Thanks @sfdcfox used object type and passed two arguments
    – SFDC
    Commented Mar 5, 2019 at 12:18

You must log in to answer this question.

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