0

I have used map as attribute type in Lightning component. In markup how can i print the value from this map? I need syntax only. I am creating map from js controller of component.

0

1 Answer 1

3

So you have to use a child component to get the values from map using javascript

for example

<component>

   <c:ChildComponent mapObject="{!v.YourMap}" mapKey="{v.mapKey}"> 

</component>

In child component

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

   <ui:outputText aura:Id="outputTextId" />

</component>

ChildComponent controller

{
    doInit : function(component, helper) {
        var mapObject= component.get('v.mapObject');
        var mapKey = component.get('v.mapKey');
        var outputText = component.find("outputTextId");

        outputText.set("v.value",mapObject[mapKey]);

    }
})
1
  • By the way i found the perfect match here which essentially resolved my query. But your answer is also relevant to question so, i marked as answer. Commented Apr 25, 2017 at 8:53

You must log in to answer this question.

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