2014-07-07 39 views
8

我是新来的百里香叶,想用一个数组和一个循环做一个简单的表。在百里香叶中创建一张桌子

我的代码如下所示:

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

基本上我的问题是,我不能在<tr>的run循环为<td>秒。有什么方法可以使这个代码工作?

这是第一位想到

回答

5

简单的解决方案:

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

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

+0

这不起作用becase th:文本没有关系的循环。 – user3073234

+0

我刚更新了我的答案。 –

5

你必须把日:文字作为标签的属性,所以

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

应该运行。