Expand my Community achievements bar.

SOLVED

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

Avatar

Level 2

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-...

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

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/sightly-how-to-iterate-thr...

 

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

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