1

I have a customer apex controller that products a payload with an json apex map of map<String, List>. once i execute the apex method the javascript i convert it with json.parse and load them on to a new js map using New Map([]). as far as i am aware the map is not empty as the console logs show that the map has values, but on the lwc page it doesnt show any txt as i used the code below

<template for:each={responseMap} for:item="mapItem">
{mapItem.key}
<template for:each={mapItem.value} for:item="innermap">
<li key={innermap.id}>{innermap.Name}</li>
</template>
</template>

Thanks and Regards

1 Answer 1

2

You cannot display map in LWC HTML.

To render a list of items, use for:each directive or the iterator directive to iterate over an array. ~ https://developer.salesforce.com/docs/platform/lwc/guide/create-lists.html

  1. Convert Map to List.
this.data = Object.entries(responseMap).map(([key, value]) => ({
   key,
   value
});
  1. Use List in HTML
<template>
   <template for:each={data} for:item="mapItem">
      {mapItem.key}
      <template for:each={mapItem.value} for:item="innermap">
         <li key={innermap.id}>{innermap.Name}</li>
      </template>
   </template>
</template>
1
  • i tried doing this with both the response map, parsed map, and the newly created map and i would always see the map empty in the console logs, could you give some more detail in regards to this, thank you
    – Cancel Ed
    Sep 6, 2023 at 5:28

You must log in to answer this question.

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