如何使用百里香叶实现折叠和展开列表?

问题描述 投票:0回答:1

我有一个HashMap(称为test),格式如下:HashMap<String,List<MyClass>>

我想将HashMap值的项目显示为可扩展的标题,从中可以找到列表中每个对象的信息。

我有以下代码,但是在扩展列表中看到的只是每个标题一行。实际上,列表中的项目会被for循环中的下一个覆盖。

<tbody>
  <tr th:each="element, iterStat  : ${test}">
    <td data-toggle="collapse" th:attr="data-target=|#demo${iterStat.count}|" th:text="${element.key}">keyvalue</td>

    <tr class="accordian-body collapse" th:id="'demo' + ${iterStat.count}" th:each="anews : ${element.value}">
      <td th:text="''">Place name</td>
      <td th:text="${anews.first_point}">First point</td>
      <td th:text="${anews.second_point}">Second point</td>
    </tr>
  </tr>
</tbody>

我应该如何更正我的代码?

html thymeleaf collapse
1个回答
0
投票

这是您想要的吗?

<tbody>
    <th:block th:each="element, iterStat  : ${test}">
        <tr>
            <td colspan="3" data-toggle="collapse" th:data-target="|.demo${iterStat.count}|" th:text="${element.key}" />
        </tr>

        <tr class="accordian-body collapse" th:class="'demo' + ${iterStat.count}" th:each="anews : ${element.value}">
            <td th:text="''">Place name</td>
            <td th:text="${anews.first_point}" />
            <td th:text="${anews.second_point}" />
        </tr>
    </th:block>
</tbody>
© www.soinside.com 2019 - 2024. All rights reserved.