Slightly - Iterate through List<Map<String,List<Pojo>>> | Community
Skip to main content
Level 2
March 2, 2024
Solved

Slightly - Iterate through List<Map<String,List<Pojo>>>

  • March 2, 2024
  • 1 reply
  • 977 views

Hi Team, I was wondering if it's possible to iterate through a list of Maps which contains a list of Pojo. This is because the actual requirement is to display a "categorized" list. i.e:

 

  • Animals
    • Bird
      • How to Take care of your bird
      • Another Page Example
    • Cat
      • how to ...
      • another Page

 

I was checking some of the past post reading how to iterate over Map but seems like none of the solutions below have worked on.. (I'm thinking if this kind of implementations is valid).

 

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/iterate-multivaluedmap-in-sightly/td-p/391808

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/map-lt-string-object-gt-in-htl/td-p/610645

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/sightly-how-to-iterate-through-map-lt-string-map-gt/td-p/196058

 

if you have any inputs or guidance in how to accomplish this. I'll be very grateful with you guys

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by arunpatidar

Hi @luis_ochoa 
could you please check

 

<!-- Assuming 'myList' is the List<Map<String, List<Pojo>>> variable available in your context --> <ul data-sly-list="${myList}"> <!-- Outer loop: Iterating through the List<Map<String, List<Pojo>>> --> <li> <!-- Extracting the map from the list item --> <sly data-sly-test="${item['myMap']}" data-sly-use.myMap="${item['myMap']}"> <p>Map Key: ${item.key}</p> <!-- Inner loop: Iterating through the Map<String, List<Pojo>> --> <ul data-sly-list="${myMap}"> <li> <!-- Extracting the list from the map item --> <sly data-sly-test="${item['myList']}" data-sly-use.myList="${item['myList']}"> <p>List Key: ${item.key}</p> <!-- Innermost loop: Iterating through the List<Pojo> --> <ul data-sly-list="${myList}"> <li>${item.property1}</li> <li>${item.property2}</li> <!-- Add more properties as needed --> </ul> </sly> </li> </ul> </sly> </li> </ul>

1 reply

arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
March 4, 2024

Hi @luis_ochoa 
could you please check

 

<!-- Assuming 'myList' is the List<Map<String, List<Pojo>>> variable available in your context --> <ul data-sly-list="${myList}"> <!-- Outer loop: Iterating through the List<Map<String, List<Pojo>>> --> <li> <!-- Extracting the map from the list item --> <sly data-sly-test="${item['myMap']}" data-sly-use.myMap="${item['myMap']}"> <p>Map Key: ${item.key}</p> <!-- Inner loop: Iterating through the Map<String, List<Pojo>> --> <ul data-sly-list="${myMap}"> <li> <!-- Extracting the list from the map item --> <sly data-sly-test="${item['myList']}" data-sly-use.myList="${item['myList']}"> <p>List Key: ${item.key}</p> <!-- Innermost loop: Iterating through the List<Pojo> --> <ul data-sly-list="${myList}"> <li>${item.property1}</li> <li>${item.property2}</li> <!-- Add more properties as needed --> </ul> </sly> </li> </ul> </sly> </li> </ul>
Arun Patidar