对于 Thymeleaf 中的每个运算符 [英] For each operator in Thymeleaf
问题描述
我在 Thymeleaf
模板中找不到用于构建简单 for-each-loop 的语法.我对 th:each=""
属性不满意,因为它复制了它所在的标签.
I can not find syntax for building simple for-each-loop in Thymeleaf
template.
I'm not satisfied with just th:each=""
attribute, because it copies tag in which it's located.
我正在寻找的是这样的:
What I'm looking for is something like:
<th:foreach th:each="...">
...block to be repeated...
</th>
或
.有什么类似的吗?
what is analogue of <c:forEach items="..." var="...">
or <t:loop source="..." value="...">
in Tapestry
. Is anything similar for that?
推荐答案
使用 th:block
如 Thymeleaf 指南中所述
Use th:block
as stated in the Thymeleaf guide
th:block
只是一个属性容器,允许模板开发人员指定他们想要的任何属性.Thymeleaf 会执行这些属性,然后简单地让块消失得无影无踪.
th:block
is a mere attribute container that allows template developers to specify whichever attributes they want. Thymeleaf will execute these attributes and then simply make the block disappear without a trace.
因此它可能很有用,例如,当创建每个元素需要多个 <tr>
的迭代表时:
So it could be useful, for example, when creating iterated tables that require more than one <tr>
for each element:
<table>
<th:block th:each="user : ${users}">
<tr>
<td th:text="${user.login}">...</td>
<td th:text="${user.name}">...</td>
</tr>
<tr>
<td colspan="2" th:text="${user.address}">...</td>
</tr>
</th:block>
</table>
这篇关于对于 Thymeleaf 中的每个运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!