6

I was testing Javascript Object Types and trying to bind them to aura attribute Collection types unsuccesfully client-side (for the most case), so I was wondering if there is a reference with a set of documented examples for each.

Collection Types

  • type[] (Array)
  • List
  • Map
  • Set

for a Map, I tried:

var myMap = new Map();
myMap.set("keyString", "value associated with 'a string'");
component.set('v.attMap', myMap);

for a Set:

 var set1 = new Set([1, 2, 3, 4, 5]); 
 component.set('v.mySet', set1);

List and type Arrays:

var array1 = ['a', 'b', 'c'];
component.set('v.myList', array1);

The only Object Types I was able to successfully bind were the List and Type Array(s).

I based my examples out of JavaScript data types and data structures

When I Try Binding my server response to a Map/Set I am able to do so successfully.

I did notice that my Proxy object(s) for Map and Set were returning the following Exception:

Exception: TypeError: Method get Map.prototype.size called on incompatible receiver # at Map.get size [as size] () at Map.remoteFunction (:2:14)

minimal reproduceable code sample:

Component.cmp

<aura:component >
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <aura:attribute name="attMap" type="Map"/>

    <aura:iteration items="{!v.attMap}" var="map">
            <tr>
              <td scope="row" data-label="Map Values">
                <div class="slds-truncate" title="{!map}"><a href="javascript:void(0);">{!map}</a></div>
              </td>
            </tr>
    </aura:iteration>
</aura:component>

Controller.js

({
    doInit : function(component, event, helper) {
        var myMap = new Map();
        myMap.set("keyString", "value associated with 'a string'");
        component.set('v.attMap', myMap);
        //--->console.log(component.get('v.attMap'));

    },
})

What would be the proper way of Binding Javascript Maps and Sets to Aura Collection Type Attributes? (an explanation backed up by documentation from the aura framework would be nice)

2
  • 1
    I suspect you may have been doing something incorrectly somewhere else. I tried this, and the types do work as you'd expect in JavaScript.
    – sfdcfox
    Mar 28, 2018 at 14:55
  • I added how and when I am trying to bind my Javascript map to the collecton type
    – glls
    Mar 28, 2018 at 15:18

1 Answer 1

1

Here the binding you have done to Map is not an issue. Rather, the iteration you are performing here is on Map but in lightning components, aura iteration works on attribute of type List, so that is the reason you are getting the error on the component.

You must log in to answer this question.

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