gpt4 book ai didi

thymeleaf - 如何使用 thymeleaf 同时迭代两个数组

转载 作者:行者123 更新时间:2023-12-05 03:12:28 28 4
gpt4 key购买 nike

我有两个数组,我想在同一个表(不同的列)中显示其内容。如何使用 indexth:each

遍历数组

这是我想要实现的目标

<table>
<tr>
<td>List1Elm1</td>
<td>List2Elm1</td>
</tr>
<tr>
<td>List1Elm2</td>
<td>List2Elm2</td>
</tr>
<tr>
<td>List1Elm3</td>
<td>List2Elm3</td>
</tr>
<tr>
<td>List1Elm4</td>
<td>List2Elm4</td>
</tr>
</table>

在这个 List1Elm1 中是列表 1 的第一个元素。

最佳答案

事实证明,没有办法同时遍历两个列表。因此,我们可以做的是遍历索引并使用索引访问列表。

<tr th:each="index : ${#numbers.sequence( 0, #arrays.length(List1)-1)}">
<td th:text="${List1[index]>List1Elm1</td>
<td th:text="${List2[index]>List2Elm1</td>
</tr>

注意:这仅适用于 ${...} 表达式,不适用于 *{...} 表达式

关于thymeleaf - 如何使用 thymeleaf 同时迭代两个数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33473298/

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