【问题标题】:how can we get two element per iteration in jstl in for each我们如何在 jstl 中为每个迭代获得两个元素
【发布时间】:2014-08-09 05:18:38
【问题描述】:

我想在 jstl 中每次迭代获得两到两个元素。我这样做有可能吗? 这是我的代码。 dataListTweets 是我在上一页设置的列表。我想从列表中每次迭代迭代两个两个元素。

<table cellpadding="2"  style="margin-left: 82px;margin-top: 11px;">
            <c:forEach items="${dataListTweets}" var="Tweets">
            <tr>
                <td width="119">${Tweets}</td>
                <td width ="168">${Tweets}</td>
            </tr>
        </c:forEach>
        <c:remove var="dataListDetails" scope="request"/>
    </table>

【问题讨论】:

    标签: jstl


    【解决方案1】:

    您可以在forEach 中指定一个step 值来迭代集合的每两项。 然后使用varStatus 获取循环的索引来定义要显示的推文。

    <table>
        <c:forEach  step="2" items="${dataListTweets}" varStatus="vs">
            <tr>
                <td width="119">${dataListTweets[vs.index]}</td>
                <td width="168">${dataListTweets[vs.index+1]}</td>
            </tr>
        </c:forEach>
    </table>
    

    【讨论】:

      猜你喜欢
      • 2021-02-14
      • 1970-01-01
      • 1970-01-01
      • 2014-06-08
      • 2016-02-03
      • 1970-01-01
      • 2023-03-19
      • 2015-12-25
      相关资源
      最近更新 更多