我想做这样的事情
<c:forEach var="item1" items="List1" var="item2" items="List2">
<p> ${item1} ${item2}</p>
</c:forEach>一种解决方案是,如果两个列表的大小相同,则迭代这两个列表
<c:forEach var="i" begin="0" end="$(fn:length(List1))">
<p> <%= List1.get(i) %> <%= List2.get(i)%> //wrong syntax
</c:forEach>有没有办法做到这一点。
发布于 2013-07-25 14:45:54
您可以调用varStatus.index来获取当前轮的索引,然后将其用作第二个列表的查找。注意List的长度,否则会抛出异常。将items设置为具有这两项中最大值的List。
<c:forEach var="element" items="${List1}" varStatus="status">
<p>
${element}
${List2[status.index]}
</c:forEach>发布于 2015-05-27 17:53:52
Array is Frist List, and B is Second List and varStatus.index to get the index of the current round and then use it as a lookup for the second list.
<c:forEach var="Array" items="${A}" varStatus="status">
<c:out value="${A}","${B[status.index]}"}/>
</c:forEach>https://stackoverflow.com/questions/17850842
复制相似问题