温馨提示:本文翻译自stackoverflow.com,查看原文请点击:html - How to implement collapsing and expanding of a list using thymeleaf?
collapse html Thymeleaf

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

发布于 2020-05-01 17:53:58

我有一个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>

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

查看更多

提问者
user1419243
被浏览
126
Metroids 2020-02-13 21:21

这是您想要的吗?

<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 th:class="|accordian-body collapse 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>