hyljava

          c:forEach的varStatus屬性

          index當前這次迭代從 0 開始的迭代索引
          count當前這次迭代從 1 開始的迭代計數
          first用來表明當前這輪迭代是否為第一次迭代的標志
          last用來表明當前這輪迭代是否為最后一次迭代的標志
          begin屬性值
          end屬性值
          step屬性值

          例:

          表格偶數行與奇數行顏色交替效果
          引標簽庫
          <%@ taglib prefix="c" uri="<%@ taglib prefix="fn" uri="<c:forEach items="${queryPromotionList}" var="vPromotion" varStatus="vstatus">
                      <c:choose>
                          <c:when test="${vstatus.index%2==0}">
                <tr bgcolor="#FFFFFF" height="40">
                          </c:when>
                          <c:otherwise>
                  <tr bgcolor="#F3F3F5" height="40">
                          </c:otherwise>
                      </c:choose>

           

             <table class=table_body_bg cellspacing=1 cellpadding=1
                      width="100%" align=center border=0>
                       <c:forEach items="${list}" var="a" varStatus="vs">

               <c:if test="${vs.count%5==1}">
                 <tr align="left" height="20">
                </c:if>             
                       <td class=table_body_td width="20%"><a href="/aam/degree/advisorAnswer.do?sfid=${a.sfid }">${a.xm }(${a.sfid })</a></td>
               <c:set var="count" value="${vs.count}"/>         //${vs.count}只在<c:forEach></c:forEach>的范圍內有值 外部引用需要把值傳出去
               </c:forEach>    
                <c:if test="${count%5==1}">
                <td class="table_body_td" width="20%"></td>
                <td class="table_body_td" width="20%"></td>
                <td class="table_body_td" width="20%"></td>
                <td class="table_body_td" width="20%"></td>
                </tr>
                </c:if>
              
                <c:if test="${count%5==2}">
                <td class="table_body_td" width="20%"></td>
                <td class="table_body_td" width="20%"></td>
                <td class="table_body_td" width="20%"></td>    
                </tr>
                </c:if>
               
                <c:if test="${count%5==3}">
                <td class="table_body_td" width="20%"></td>
                <td class="table_body_td" width="20%"></td>
                </tr>
                </c:if>
               
                <c:if test="${count%5==4}">
                <td class="table_body_td" width="20%"></td>
                </tr>
                </c:if>

                <c:if test="${count%5==0}">
                </tr>
                </c:if>
                       </table>

           

           

           

          不論是對整數還是對集合進行迭代, <c:forEach> 剩余的屬性 varStatus 所起的作用相同。和 var 屬性一樣, varStatus 用于創建限定了作用域的變量。不過,由 varStatus 屬性命名的變量并不存儲當前索引值或當前元素,而是賦予 javax.servlet.jsp.jstl.core.LoopTagStatus 類的實例。該類定義了一組特性,它們描述了迭代的當前狀態,下面列出了這些特性:

           

          特性 Getter 描述
          current getCurrent() 當前這次迭代的(集合中的)項
          index getIndex() 當前這次迭代從 0 開始的迭代索引
          count getCount() 當前這次迭代從 1 開始的迭代計數
          first isFirst() 用來表明當前這輪迭代是否為第一次迭代的標志
          last isLast() 用來表明當前這輪迭代是否為最后一次迭代的標志
          begin getBegin() begin 屬性值
          end getEnd() end 屬性值
          step getStep() step 屬性值

           

          posted on 2012-06-08 23:57 何云隆 閱讀(31530) 評論(2)  編輯  收藏 所屬分類: JSTL

          評論

          # re: c:forEach的varStatus屬性 [未登錄] 2014-09-15 15:32

          222  回復  更多評論   

          # re: c:forEach的varStatus屬ddddd性 2014-09-15 17:54 dddddda as

          das   回復  更多評論   

          主站蜘蛛池模板: 巴林左旗| 淳化县| 桦甸市| 黔江区| 莆田市| 磐安县| 麻江县| 阜南县| 田林县| 台安县| 万州区| 天柱县| 揭阳市| 栾川县| 湘阴县| 伊川县| 杭锦后旗| 怀柔区| 河西区| 五大连池市| 霍山县| 抚顺市| 文山县| 鲁山县| 河西区| 新蔡县| 本溪市| 海晏县| 绍兴县| 和平县| 长春市| 勐海县| 北辰区| 永安市| 西华县| 孟津县| 鹤山市| 达州市| 绥德县| 安岳县| 梧州市|