Html 在 thymeleaf 中创建一个表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24614113/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Create a table in thymeleaf
提问by user3073234
I'm new to thymeleaf and am trying to make a simple table using an array and an each loop.
我是 thymeleaf 的新手,正在尝试使用数组和 each 循环制作一个简单的表格。
My code looks like this:
我的代码如下所示:
<!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>
Basically my problem is that I can't run the loop as <td>
s within <tr>
s. Is there any way that this code could work?
基本上我的问题是我不能<td>
在<tr>
s 中以s 的形式运行循环。有什么办法可以让这段代码工作吗?
采纳答案by Slava Semushin
Simple solution which comes to mind first:
首先想到的简单解决方案:
<th:block th:each="smokeTest : ${smokeTests}">
<tr>
<td th:text="${smokeTest.name}">A Smoke Test'</td>
</tr>
</th:block>
回答by niels
You must put th:text as an attribute of a tag, so
你必须把 th:text 作为标签的一个属性,所以
<tr th:each="smokeTest : ${smokeTests}">
<td th:text="${smokeTest.name}">A Smoke Test'</td>
</tr>
should run.
应该运行。
回答by Rashed
Although, it's late answer. It's work more specifically, like
虽然,这是迟到的答案。它的工作更具体,比如
<tr th:each="smokeTest : ${smokeTests}">
<td><p th:text="${smokeTest.name}"></p></td>
</tr>