我有模板,四个人用的li
我应该拥有的元素ul
元素。我该怎么做?现在我有类似的东西:
<div th:each="excursion,iterStat : ${excursions}">
<ul th:if="${iterStat.index}/4 == 0">
<li>
<a th:href="@{/excursion/{id}(id=${excursion.excursionId})}"><img src="/template/images/garden1.jpg" alt="Image" /></a>
<h2 th:text="${excursion.title}"></h2>
<p th:text="${#strings.abbreviate(excursion.description,128)}"></p>
</li>
</ul>
</div>
我想if
条件将应用于 elveryul
元素,但它隐藏了所有东西,包括li
元素。
根据您的评论,您需要一个包含 4 个项目的列表,下面的内容就可以解决问题。如果您遇到问题请告诉我
<ul>
<div th:each="excursion,iterStat : ${excursions}" th:if="${iterStat.index}<5">
<li>
<a th:href="@{/excursion/{id}(id=${excursion.excursionId})}"><img src="/template/images/garden1.jpg" alt="Image" /></a>
<h2 th:text="${excursion.title}"></h2>
<p th:text="${#strings.abbreviate(excursion.description,128)}"></p>
</li>
</div>
</ul>
编辑1:
根据提供的数据进一步审查会产生另一种可能性。
在传递之前,在 Controller 中使用 Map 而不是批量列表:
Map<String, List<Excursion>> excursionsList;
确保将每次旅行限制为 4 次(根据您的需要)。
然后在 Thymeleaf 中迭代地图。
<div th:each="excursion,rowStat : *{excursionsList}">
<ul>
<div th:each="list,iterStat : *{excursion[__${rowStat.index}__].value}">
//your code for each list item information such as excursionId, description etc.
</div>
</ul>
</div>
这应该会清理你的代码堆并根据你的需要进行制作。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)