Activity Forums Salesforce® Discussions How to iterate map in Salesforce Lightning Component?

  • PRANAV

    Member
    September 22, 2016 at 5:37 am

    Hi Tanu,

    You can only defined to iterate over a List, According to the Aura docs.

    If you have not seen the Aura docs app before, it is available with any Salesforce instance by modifying the URL:

    [your instance stuff].salesforce.com/auradocs/reference.app

    Or to navigate to the page for the iteration component:

    [your instance stuff].salesforce.com/auradocs/reference.app#reference?descriptor=aura:iteration&defType=component

    Hope this helps you.

    Thanks

  • Parul

    Member
    September 28, 2018 at 5:17 pm

    <aura:component controller="MyMapClass">
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <aura:attribute name="myMap" type="Map" />
    {!v.myMap.key1} <br/>
    {!v.myMap.key2}
    </aura:component>
    ({
    doInit: function(component, event, helper) {

    var action = component.get('c.getMyMap');

    action.setCallback(this,function(response){
    alert(JSON.stringify(response.getReturnValue()));
    component.set('v.myMap',response.getReturnValue());
    });
    $A.enqueueAction(action);
    }
    })
    public class MyMapClass {
    @AuraEnabled
    public static map<String,String> getMyMap(){
    Map<String,String> Mymap = new Map<String,String>();
    Mymap.put('key1','apple');
    Mymap.put('key2','mango');
    return Mymap;
    }
    }
    here is a simple example to use map in lightning component and use @AuraEnabled in you apex class method
    component

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos