在百里香花中创建一张桌子

use*_*234 12 html each html-table thymeleaf

我是thymeleaf的新手,我正在尝试使用数组和每个循环创建一个简单的表.

我的代码看起来像这样:

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Smoke Tests</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<table border="1" style="width:300px">
    <tr>
        <td>Test Name</td>
    </tr>
    <tr th:each="smokeTest : ${smokeTests}">
        <td>
            th:text="${smokeTest.name}">A Smoke Test'
        </td>
    </tr>
</table>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

基本上我的问题是我不能在<td>s内运行循环<tr>.这段代码有什么办法可行吗?

nie*_*els 11

你必须把th:text作为标签的属性,所以

<tr th:each="smokeTest : ${smokeTests}">
   <td th:text="${smokeTest.name}">A Smoke Test'</td>
</tr>
Run Code Online (Sandbox Code Playgroud)

应该跑.


Sla*_*hin 6

首先想到的简单解决方案:

<th:block th:each="smokeTest : ${smokeTests}">
    <tr>
        <td th:text="${smokeTest.name}">A Smoke Test'</td>
    </tr>
</th:block>
Run Code Online (Sandbox Code Playgroud)

详情:http://www.thymeleaf.org/whatsnew21.html#bloc