迭代jstl中的多项 [英] iterating of muliple items in jstl
问题描述
我有这个要求在jstl中同时迭代3个以上的列表.遍历我们使用的单个列表
I have this requirement to iterate over 3 lists at the same time in jstl. for iterating over a single list we use
<c:forEach var = "mfgn" items = "${requestScope.mfgNumber}" varStatus = "status">
do something;
</c:forEach>
我需要做类似
<c:forEach var = "mfgn" var = "issue" items = "${requestScope.mfgNumber}" items = "${requestScope.something" varStatus = "status">
mfgNumber;
</c:forEach>
这是可能的还是通过其他方式同时遍历多个列表.
is this possible or there an otherway to iterate over multiple lists at the same time.
推荐答案
如果它们的大小相同,则有两个选项,假设它们分别为List<Integer>
和List<String>
:
If they have the same size, then there are two options, assuming that it are List<Integer>
and List<String>
:
-
将它们与实体合并到单个列表中,这些实体又将单个列表中的其他列表的项目重复出现,例如
List<ManfacturerIssue>
,其中ManfacturerIssue
是一个Javabean类,其中包含Integer number
和String issue
特性.这样,您最终可以这样做:
Merge them in a single list with entities which in turn repesents the items of each other list in a single class like
List<ManfacturerIssue>
where theManfacturerIssue
is a javabean class which containsInteger number
andString issue
properties. This way you can end up doing:
<c:forEach items="${mfgIssues}" var="mfgIssue">
${mfgIssue.number}, ${mfgIssue.issue}
</c:forEach>
而是通过索引进行迭代,但这很难看,并且无法通过(填写)来维护:
Iterate by index instead, this is however ugly and unmaintainable as (fill in):
<c:forEach begin="0" end="${fn:length(mfgNumbers) - 1}" varStatus="loop">
${mfgNumbers[loop.index]}, ${issues[loop.index]}
</c:forEach>
这篇关于迭代jstl中的多项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!