2014-07-07 41 views
8

Ben thymeleaf için yeni ve bir dizi ve her döngü kullanarak basit bir tablo yapmaya çalışıyorum.Thymeleaf tablosunda bir tablo oluşturun

Benim kod şöyle görünür:

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

benim sorunum ben <tr> s içinde <td> s olarak döngü koşamam olmasıdır. Bu kodun çalışabilmesi için herhangi bir yolu var mı? İlk akla gelen

cevap

5

Basit çözüm:

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

Detayları: çalışmalıdır böylece

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

, etiketlere bir niteliği olarak metne: http://www.thymeleaf.org/whatsnew21.html#bloc

+0

Bu işe yaramıyor: metnin ilmiyle bir ilişkisi yoktur. – user3073234

+0

Cevabımı yeni güncelledim. –

5

Sen inci koymak gerekir.

İlgili konular