Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nested loop in select option in thymeleaf over map?

I am passing Map which containg Integer and list from my controller class to view. Inside view I have select option in which i want to show only List value in option but i don't know how to implement this. Please help me to do this.

controller

Map<Integer, List<String>> deviceidsAndwhatToUpdateText = new HashedMap<Integer, List<String>>();

view

<select class="form-control select-checkbox"
                id="WhatToUpdate" multiple="multiple">
                    <option th:each="idsAndText : ${deviceidsAndwhatToUpdateText}"

                         th:value="${idsAndText.value}"
                        th:utext="${idsAndText.value}">Wireframe</option>

            </select>
like image 221
mohit Avatar asked Jan 26 '26 15:01

mohit


1 Answers

This will list all the String in your map, is that what you want?

<select class="form-control select-checkbox" id="WhatToUpdate" multiple="multiple">
  <th:block th:each="idsAndText : ${deviceidsAndwhatToUpdateText}">
    <option th:each="text : ${idsAndText.value}" th:value="${text}" th:text="${text}" />
  </th:block>
</select>
like image 143
Metroids Avatar answered Jan 28 '26 09:01

Metroids



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!