2016-03-01 74 views
0

我有一个时间序列,在thymeleaf模板中的foreach范围,也是一个hashmap对象。访问范围变量索引在Thymeleaf中的地图对象

我想通过范围变量访问hashmap值,但我无法弄清楚如何。这是我迄今为止最好的尝试:

 <td th:each="day : ${DaySequence}" class="openable" th:attr="[email protected]{/task/frame/{nbrplt}/{week}/{day_num}(nbrplt=${vehicle.numberPlate}, week=${week.weekNumber}, day_num=${day}) }"> 
        <ul> 
         <li th:each="task : ${vehicle.vehicleTaskByDays[day]}" th:text="${task.toString()}"></li> 
         <!-- <li th:text="${day}"></li> --> 
        </ul> 
        </td> 

但百里香叶无法解析这一点。在一些论坛上,我发现这是解决方案:

<li th:each="task : ${vehicle.vehicleTaskByDays[__${day}__]}" th:text="${task.toString()}"></li> 

但它也不起作用,所以,我怎么能访问日之间的天变“[]”?

回答

1

尝试用HasMap的get方法:

 <td th:each="day : ${DaySequence}" class="openable" th:attr="[email protected]{/task/frame/{nbrplt}/{week}/{day_num}(nbrplt=${vehicle.numberPlate}, week=${week.weekNumber}, day_num=${day}) }"> 
       <ul> 
        <li th:each="task : ${vehicle.vehicleTaskByDays.get(day)}" th:text="${task.toString()}"></li> 
        <!-- <li th:text="${day}"></li> --> 
       </ul> 
       </td>