簡體   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