对于Thymeleaf中的每个运算符 [英] For each operator in Thymeleaf

查看:186
本文介绍了对于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>

Tapestry中的<c:forEach items="..." var="..."><t:loop source="..." value="...">类似.有什么类似的东西吗?

what is analogue of <c:forEach items="..." var="..."> or <t:loop source="..." value="..."> in Tapestry. Is anything similar for that?

推荐答案

按照Thymeleaf指南中的说明使用th:block

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆