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.

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]);

    }
})
| improve this answer | |
  • 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. – Tejas Kapasi Apr 25 '17 at 8:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.