html - 在 thymeleaf 中创建一个表

标签 html html-table each thymeleaf

我是 thymeleaf 的新手,我正在尝试使用数组和 each 循环制作一个简单的表格。

我的代码是这样的:

<!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>

基本上我的问题是我不能以 <td> 运行循环在 <tr> 内秒。有什么方法可以让这段代码起作用吗?

最佳答案

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

<tr th:each="smokeTest : ${smokeTests}">
   <td th:text="${smokeTest.name}">A Smoke Test'</td>
</tr>

应该运行。

关于html - 在 thymeleaf 中创建一个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24614113/

相关文章:

C++如何将关键字 'friend'与来自两个类的成员函数一起使用相互包含

javascript - 有什么办法可以解决 HTML5 Canvas 大小限制吗?

javascript - 如何直接链接到特定的 JavaScript 选项卡?

javascript - DataTable,导出为 pdf 不能正常使用两个标题和 colspan

css - Chrome 将宽度为 0 的表格单元格显示为 1px

javascript - 取消选中在 Angular 5 中通过条件选中并卡住的复选框

javascript - Jquery 每次替换innerHtml

html - Jade-Template 中带有 if 条件的每个循环

javascript - php javascript过滤内容

javascript - 单击按钮缩放图像