2014-07-07 2 views
8

저는 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> 

내 문제는 내가 <tr> 초 이내에 <td>들로 루프를 실행할 수 있다는 것입니다. 이 코드가 작동 할 수있는 방법이 있습니까? 먼저 떠오르는

답변

5

간단한 해결책 :

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

세부 사항 : 실행해야합니다 그래서

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

, 태그의 속성으로 텍스트 : http://www.thymeleaf.org/whatsnew21.html#bloc

+0

텍스트가 루프와 관련이 없기 때문에 이렇게 작동하지 않습니다. – user3073234

+0

방금 ​​내 대답을 업데이트했습니다. –

5

당신은 번째 넣어해야합니다.

관련 문제