gpt4 book ai didi

javascript - 如何设置限制th :each loop in HTML

转载 作者:太空宇宙 更新时间:2023-11-04 14:37:18 25 4
gpt4 key购买 nike

如何在 thymeleaf HTML 页面中为 each 循环设置限制?

例如:

<select id="places" onchange="onPlaceChange();">
<option value="0">Select Place</option>
<option th:each="p:${places}" th:text="${p.place_Name}" th:value="${p.id}"></option>
</select>

此代码循环遍历数据库中的项目,limit 是列表的长度。

这里的列表长度是 14,我想将该限制设置为 7,我该怎么做?

最佳答案

关键是使用迭代状态机制以及 th:ifth:unless 条件属性。

相关引用资料在:

因此在您的情况下,它看起来类似于:

<option th:each="p,pStat : ${places}" th:text="${p.place_Name}" th:value="${p.id}" th:unless="${pStat.index > 7}"></option>

编辑:这个答案是为 Thymeleaf 2.1(当时)编写的,但应该以相同或相似的方式与 3.0 一起使用。看: https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html

关于javascript - 如何设置限制th :each loop in HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23240994/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com