繁体   English   中英

使用表在指定结构的jsp页面中安排动态列表

[英]arranging dynamic list in jsp page in the specified structure using table

我有一个动态生成的列表。我希望使用表显示此列表。 结构应如下

假设如果我有6个值,则前3个值应该在第一行中,而后3个值应该在第二行中,我该如何动态地进行操作

<table>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</table>

上面的tr结构应该每3个元素重复一次

我尝试使用divs.its工作,但我希望使用表来实现相同的目的。 帮帮我。

问候,拉维。

我的意思是列表是bean的集合。在每个bean中我都有一些value.so,我的表如下所示

这是正在迭代的列表

<c:forEach value="#{theList}" var="item">

<div class="customer">
<p>${item.field1}</p>
<p>${item.field1}</p>
</div>

</c:foreach>

从上面来看,div客户应具有以下结构

  • 前三个bean应该在第一行中包含3列
  • 第二三个豆应该在第二行,三列
  • 继续...

使用JSTL:

<table>
    <c:forEach items="#{theList}" var="item" varStatus="i">
    <c:if test="${i.index % 3 == 0 or i.begin}">
    <tr>
    </c:if>
        <td>${item.field}</td>
    <c:if test="${i.index % 3 == 0 or i.last}">
    </tr>
    </c:if>
    </c:forEach>
</table>
<c:forEach items="${loopableObject}" var="theObject" varStatus="theCount">
 <table>
  <tr>
    <c:if test='${(status.index) lt 3}'>

    <td>${item.field1}</td>
    <td>${item.field2}</td>
    <td>${item.field3}</td>

   </c:if>
 </tr>

 <tr>
   <c:if test='${(status.index) gt 2}'>
    <td>${item.field1}</td>
    <td>${item.field2}</td>
    <td>${item.field3}</td>

   </c:if>
</tr>
</table>
</c:forEach>

虽然我还没有测试过,但类似的东西可能会起作用。

<table>
    <tr>
        <c:forEach var="item" items="${yourList}" varStatus="loopStatus">
            <c:if test="${loopStatus.index % 3 == 0 }"><tr></c:if>
                <td><c:out value="${item}"/></td>
            <c:if test="${loopStatus.index % 3 == 0 }"></tr></c:if> 
        </c:forEach>
        <c:if test="${yourList.size % 3 != 0 }"></tr></c:if>
</table>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM