的Thymeleaf 2.1.4官方文档演示for each
用法如下:Thymeleaf:如何在使用th时排除外部标签:每个?
<tr th:each="prod : ${prods}" th:class="${prodStat.odd}? 'odd'">
<td th:text="${prod.name}">Onions</td>
<td th:text="${prod.price}">2.41</td>
...
</tr>
它产生在每个迭代中,这是在这种情况下,完美契合一个<tr>
。但在我的情况下,我不需要外部标签(在这里,<tr>
)。
我用例是一个递归的方式产生<bookmark>
标签,没有任何其他标记包括,和<bookmark>
标签必须包含名称和href属性。
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<body>
<div th:fragment="locationBookmark(location)">
<bookmark th:each="map : ${location.subMaps}">
<bookmark th:name="${map.name}"
th:href="'#'+${map.id}" th:include=":: locationBookmark(${map})">
</bookmark>
</bookmark>
</div>
</body>
</html>
的包边:
<bookmark th:include="bookmark : locationBookmark(${rootLocation})"/>
非常感谢。
你能提供标签的样品要不是附近的外标签? –
@PavelUvarov我的用例添加,请参阅我的问题。 – July
让我猜测:你想制作n级别的儿童标签吗?我认为是因为:书签不是html标签,因为不建议不要关闭带有内容的标签。如果我是对的 - 你应该以递归的方式创建和使用一些子模板。我不想让ThymeLeaf说你应该怎么做,但我确定知道这是可能的 - 请仔细阅读他们的文档。 –