snd*_*ndu 5 html each loops for-loop thymeleaf
我有一个名为“通知”的列表,我使用 Thymeleaf“每个方法”来一一访问其元素。我可以成功地做到这一点,如下所示。
<li th:each="n : *{notifications}">
<h4 type="text" th:text="*{n.message}"></h4>
</li>
Run Code Online (Sandbox Code Playgroud)
注意:“message”是我需要从列表中检索的属性。
如何以相反的顺序访问元素?例如,如果这是我当前的输出,
Cat
Dog
Rat
Run Code Online (Sandbox Code Playgroud)
我怎样才能得到这样的输出?
Rat
Dog
Cat
Run Code Online (Sandbox Code Playgroud)
如果可能的话,我会在服务器端反转它。如果你不想这样做,也许这样的事情适合你:
<li th:each="i : ${#numbers.sequence(notifications.size() - 1, 0, -1)}">
<h4 type="text" th:text="${notifications[i].message}"></h4>
</li>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5363 次 |
最近记录: |