迭代jstl中的多项 [英] iterating of muliple items in jstl

查看:58
本文介绍了迭代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>:

  1. 将它们与实体合并到单个列表中,这些实体又将单个列表中的其他列表的项目重复出现,例如List<ManfacturerIssue>,其中ManfacturerIssue是一个Javabean类,其中包含Integer numberString issue特性.这样,您最终可以这样做:

  1. 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 the ManfacturerIssue is a javabean class which contains Integer number and String 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屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆