gpt4 book ai didi

html - Thymeleaf:如何以相反的顺序遍历列表?

转载 作者:太空宇宙 更新时间:2023-11-04 13:07:33 24 4
gpt4 key购买 nike

我有一个名为“通知”的列表,我使用 Thymeleaf“每种方法”来逐个访问其元素。我可以成功地做到这一点如下。

<li th:each="n : *{notifications}"> 
<h4 type="text" th:text="*{n.message}"></h4>
</li>

注意:'message' 是我需要从列表中检索的属性。

如何以相反的顺序访问元素?例如,如果这是我当前的输出,

Cat
Dog
Rat

我怎样才能得到这样的输出?

Rat
Dog
Cat

最佳答案

如果可能的话,我会在服务器端反转它。如果你不想那样做,也许这样的事情对你有用:

<li th:each="i : ${#numbers.sequence(notifications.size() - 1, 0, -1)}"> 
<h4 type="text" th:text="${notifications[i].message}"></h4>
</li>

关于html - Thymeleaf:如何以相反的顺序遍历列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38572491/

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