【问题标题】:Nested tables with thymeleaf带百里香的嵌套表
【发布时间】:2017-09-02 21:19:28
【问题描述】:

我正在尝试让 thymeleaf 页面在页面上显示类似以下内容:

Question 1:
answer 1
answer 2
answer 3
etc...

页面中答案或问题的数量未知。但如果需要,可以从数据库中计算出来。

我正在使用 model.addAttribute 传递两个单独的列表对象。一种叫做回答,一种叫做调查。我知道它们都有效,我可以打印问题列表或答案列表,但不能同时以这种格式打印。

我目前在我的 HTML 页面中有这段代码

<table class="table table-hover">

    <tr th:each="survey : ${survey}">
        <td th:text="${survey.name}">

            <table class="second table">
                <tr th:each="answer : ${answer}">
                    <td th:text="${answer.name}"></td>
                </tr>
            </table>
        </td>
    </tr>

</table>

如何嵌套循环,以便可以在页面中显示它们,如开头所示?

更清楚一点:问题 = 调查名称和答案 = 答案名称

【问题讨论】:

  • 代码有什么问题?您的代码似乎正确,是否有任何错误或网站上没有出现某些内容?
  • 第一个出现在页面上,第二个没有出现,但我现在明白了。不知道为什么这个版本不起作用。

标签: java html nested thymeleaf


【解决方案1】:

如果有人想知道这里,您可以使用这样的嵌套列表:

               <table>
                <span th:each="survey : ${survey}">
                    <h1 th:text="${survey.name}"></h1>
                    <td>
                        <tr th:each="answer: ${answer}">
                            <p th:text="${answer.name}"></p>
                        </tr>
                    </td>
                </span>
              </table>

【讨论】:

    猜你喜欢
    • 2013-11-26
    • 1970-01-01
    • 2020-12-30
    • 2021-01-25
    • 2015-06-01
    • 1970-01-01
    • 2018-07-08
    • 2017-06-29
    • 2021-01-09
    相关资源
    最近更新 更多