<c:forEach>的自动序号

本文详细介绍了JSP中c:forEach标签的使用方法,特别是varStatus属性的功能,包括如何通过它获取当前迭代元素的索引、计数、是否为首个或末尾元素等信息。
<!--
c:forEach中的varStatus属性。指向一个字符串,该字符串引用一个对象。 map.put("vs",Object);这个对象记录着当前遍历的元素的一些信息:
getIndex():返回索引。从0开始
getCount():返回计数。从1开始
isLast():是否是最后一个元素
isFirst():是否是第一个元素

-->
<c:forEach items="${list}" var="num" varStatus="vs">
<tr>
<td>${num}</td>
<td>${vs.index}</td>
<!-- 自动序号 -->
<td>${vs.count}</td>
<td>${vs.first}</td>
<td>${vs.last}</td>
</tr>
</c:forEach>
<table id="tabContent" class="item" style="margin: 0px auto;width: 100%;word-break:break-all;text-align: center;"> <colgroup> <col width="10%;"> <col width="15%;"> <col width="10%;"> <col width="25%;"> <col width="10%;"> <col width="10%;"> <col width="10%;"> <col width="10%;"> </colgroup> <thead> <tr> <td nowrap="nowrap" style="border-bottom:none;height:30px;" nowrap="nowrap" class="A">序号</td> <td nowrap="nowrap" style="border-bottom:none;" nowrap="nowrap" class="A">检验项目</td> <td nowrap="nowrap" style="border-bottom:none;" nowrap="nowrap" class="A">条款</td> <td nowrap="nowrap" style="border-bottom:none;" nowrap="nowrap" class="A">检验依据要求</td> <td nowrap="nowrap" style="border-bottom:none;" nowrap="nowrap" class="A">判定原则</td> <td nowrap="nowrap" style="border-bottom:none;" nowrap="nowrap" class="A">检验结果</td> <td nowrap="nowrap" style="border-bottom:none;" nowrap="nowrap" class="A">单项评价</td> <td nowrap="nowrap" style="border-bottom:none;" nowrap="nowrap" class="A">检验人</td> </tr> </thead> <tbody> <c:forEach items="${subjects }" var="dataRow" varStatus="status1"> <tr class="subTr"> <td name="ss" class="C handleTd lcs_snum">${status1.index+1}</td> <c:set var="bzgdIsEmpty" value="${empty fn:trim(dataRow.lcs_bzgd) || fn:trim(dataRow.lcs_bzgd) eq '/' }"/> <c:set var="pdyjIsEmpty" value="${empty fn:trim(dataRow.lcs_pdyj) || fn:trim(dataRow.lcs_pdyj) eq '/' }"/> <c:set var="jyjgIsEmpty" value="${empty fn:trim(dataRow.lcs_jyjg) || fn:trim(dataRow.lcs_jyjg) eq '/' }"/> <c:set var="jyjlIsEmpty" value="${empty fn:trim(dataRow.lcs_jyjl) || fn:trim(dataRow.lcs_jyjl) eq '/' }"/> <c:choose> <c:when test="${(bzgdIsEmpty && jyjlIsEmpty) || (pdyjIsEmpty && jyjgIsEmpty && jyjlIsEmpty ) }"> <td class="C bigSub" style="height:35px;padding-left: 10px">${dataRow.lcs_jyxm}</td> <td class="C">${dataRow.lcs_bztk}</td> <c:if test="${bzgdIsEmpty}"> <td style="padding-left: 2px" colspan="5" class="notDef"></td> </c:if> <c:if test="${!bzgdIsEmpty}"> <td class="C" style="text-align: left;">${dataRow.lcs_bzgd }</td> <td style="padding-left: 2px" colspan="4" class="notDef"></td> </c:if> </c:when> <c:otherwise> <td class="C comSub handleTd" lcs_cma="${empty dataRow.lcs_cma?'':dataRow.lcs_cma }" dataValue="${not empty dataRow.lcs_jyxm?dataRow.lcs_jyxm:dataRow.lcs_bztk}" style="height:35px;" >${dataRow.lcs_jyxm}</td> <td class="C">${dataRow.lcs_bztk}</td> <td class="C" style="text-align: left;">${dataRow.lcs_bzgd }</td> <td class="C">${dataRow.lcs_pdyj }</td> <td class="C">${dataRow.lcs_jyjg}</td> <td class="C">${dataRow.lcs_jyjl}</td> <td class="C">${dataRow.lcs_jyry }</td> </c:otherwise> </c:choose> </tr> </c:forEach> </tbody> </table>
12-05
<table id="t2" height="475px" style="width:92%;margin-top:0px; font-size: 14px;border-bottom: 0px;" border="1" bordercolor="#000"> <tr> <td width="1.5%" style="border:0;"></td> <td width="18%" align="left" style="border:0;padding-left:15px;" height="25px">检验项目</td> <td width="36%" align="left" style="border:0;padding-left:30px;">标准规定</td> <td width="26%" align="left" style="border:0;padding-left:25px;">检验结果</td> <td width="1.5%" style="border:0;"></td> </tr> <c:forEach items="${map.list }" var="subject" varStatus="status0"> <c:choose> <c:when test="${subject.lcs_jydl=='000'||subject.lcs_jydl=='/'}"> <tr> <td style="border:0;"></td> <td align="left" valign="top" class="td1" style="border:0;padding-left:13px;">    ${subject.lcs_jyxm }</td> <td align="left" valign="top" class="td1" style="border:0;padding-left:30px;word-break:break-all;">${subject.lcs_bzgd }</td> <td align="left" valign="top" class="td1" style="border:0;padding-left:25px;height:20px;">${subject.lcs_jyjg }<c:if test="${fn:contains(subject.lcs_jyjl ,'不') }">(不符合规定)</c:if></td> <td style="border:0;"></td> </tr> </c:when> <c:otherwise> <tr> <td style="border:0;"></td> <td align="left" class="td1" style="border:0;height:20px;padding-left:13px;">【${subject.lcs_jydl }】</td> <td align="left" class="td1" style="border:0;"></td> <td align="left" class="td1" style="border:0;"></td> <td style="border:0;"></td> </tr> <tr> <td style="border:0;"></td> <td align="left" class="td1" valign="top" style="border:0;padding-left:13px;">    ${subject.lcs_jyxm }</td> <td align="left" class="td1" valign="top" style="border:0;padding-left:30px;word-break:break-all;">${subject.lcs_bzgd }</td> <td align="left" class="td1" valign="top" style="border:0;padding-left:25px;height:20px;">${subject.lcs_jyjg } <c:if test="${fn:contains(subject.lcs_jyjl ,'不') }">(不符合规定)</c:if> </td> <td style="border:0;"></td> </tr> </c:otherwise> </c:choose> </c:forEach> <tr> <td align="center" valign="top" style="border-bottom: 0px;border-bottom: 0px;border:0;" colspan=5>---------以下空白---------</td> </tr> </table>上述代码根据下面代码<table id="tabContent" class="item" style="margin: 0px auto;width: 100%;word-break:break-all;text-align: center;"> <colgroup> <col width="10%;"> <col width="15%;"> <col width="10%;"> <col width="25%;"> <col width="10%;"> <col width="10%;"> <col width="10%;"> <col width="10%;"> </colgroup> <thead> <tr> <td nowrap="nowrap" style="border-bottom:none;height:30px;" nowrap="nowrap" class="A">序号</td> <td nowrap="nowrap" style="border-bottom:none;" nowrap="nowrap" class="A">检验项目</td> <td nowrap="nowrap" style="border-bottom:none;" nowrap="nowrap" class="A">条款</td> <td nowrap="nowrap" style="border-bottom:none;" nowrap="nowrap" class="A">检验依据要求</td> <td nowrap="nowrap" style="border-bottom:none;" nowrap="nowrap" class="A">判定原则</td> <td nowrap="nowrap" style="border-bottom:none;" nowrap="nowrap" class="A">检验结果</td> <td nowrap="nowrap" style="border-bottom:none;" nowrap="nowrap" class="A">单项评价</td> <td nowrap="nowrap" style="border-bottom:none;" nowrap="nowrap" class="A">检验人</td> </tr> </thead> <tbody> <c:forEach items="${subjects }" var="dataRow" varStatus="status1"> <tr class="subTr"> <td name="ss" class="C handleTd lcs_snum">${status1.index+1}</td> <c:set var="bzgdIsEmpty" value="${empty fn:trim(dataRow.lcs_bzgd) || fn:trim(dataRow.lcs_bzgd) eq '/' }"/> <c:set var="pdyjIsEmpty" value="${empty fn:trim(dataRow.lcs_pdyj) || fn:trim(dataRow.lcs_pdyj) eq '/' }"/> <c:set var="jyjgIsEmpty" value="${empty fn:trim(dataRow.lcs_jyjg) || fn:trim(dataRow.lcs_jyjg) eq '/' }"/> <c:set var="jyjlIsEmpty" value="${empty fn:trim(dataRow.lcs_jyjl) || fn:trim(dataRow.lcs_jyjl) eq '/' }"/> <c:choose> <c:when test="${(bzgdIsEmpty && jyjlIsEmpty) || (pdyjIsEmpty && jyjgIsEmpty && jyjlIsEmpty ) }"> <td class="C bigSub" style="height:35px;padding-left: 10px">${dataRow.lcs_jyxm}</td> <td class="C">${dataRow.lcs_bztk}</td> <c:if test="${bzgdIsEmpty}"> <td style="padding-left: 2px" colspan="5" class="notDef"></td> </c:if> <c:if test="${!bzgdIsEmpty}"> <td class="C" style="text-align: left;">${dataRow.lcs_bzgd }</td> <td style="padding-left: 2px" colspan="4" class="notDef"></td> </c:if> </c:when> <c:otherwise> <td class="C comSub handleTd" lcs_cma="${empty dataRow.lcs_cma?'':dataRow.lcs_cma }" dataValue="${not empty dataRow.lcs_jyxm?dataRow.lcs_jyxm:dataRow.lcs_bztk}" style="height:35px;" >${dataRow.lcs_jyxm}</td> <td class="C">${dataRow.lcs_bztk}</td> <td class="C" style="text-align: left;">${dataRow.lcs_bzgd }</td> <td class="C">${dataRow.lcs_pdyj }</td> <td class="C">${dataRow.lcs_jyjg}</td> <td class="C">${dataRow.lcs_jyjl}</td> <td class="C">${dataRow.lcs_jyry }</td> </c:otherwise> </c:choose> </tr> </c:forEach> </tbody> </table> <script type="text/javascript" src="js/custom/ylqxbgsPrintTable.js?v=<%=System.currentTimeMillis() %>"></script> <script type="text/javascript"> $(function() { $("#tabContent td,#basicInfo td").not(".notDef").each(function(){ var val = $(this).text().trim(); if(!val)$(this).text("-"); }) $headerInfo = $($("#headerInfo").html()); $("#basicInfo1").before($headerInfo.clone()); $headerInfo.find(".ssss").html("报 告 底 稿 照 片 页") $(".pictures").before($headerInfo); rowHeight(); var lcs_snum = 1; //处理检验项目一致的(合并) $(".item:visible").each(function(){ var beginTr; $(this).find("tbody .subTr").each(function(){ //不是开始行,是普通项目,项目一致 if(beginTr && $(this).find(".comSub").length>0 && $(this).find(".comSub").attr("dataValue").trim() == beginTr.find(".comSub").attr("dataValue").trim() && $(this).find(".comSub").attr("lcs_cma") == beginTr.find(".comSub").attr("lcs_cma")){//普通项目和项目一致 $(this).find(".handleTd").remove(); beginTr.find(".handleTd").prop("rowspan",beginTr.find(".comSub").prop("rowspan")+1); return; } beginTr = $(this).find(".bigSub").length>0?"":$(this); $(this).find(".lcs_snum").text(lcs_snum++); }) }) $(".headerInfo:visible").eq(0).remove(); $(".pageNum:visible").each(function(index){ $(this).text("第 "+(index+1)+" 页 共 "+$(".pageNum:visible").length+" 页"); }) window.print(); }); function rowHeight() { var pageHeight = 1175-50; var basicHeight = $("#basicInfo").outerHeight(true); $("#tabContent").printTable({ mode : "rowHeight", header : "#headerInfo", footer : "#footerInfo", firstPageHeight:pageHeight-basicHeight+$("#headerInfo").outerHeight(true), /* pageNumStyle : "第#p页,共#P页", pageNumClass : ".pageNum", */ pageHeight : pageHeight, lastPageFill:'<tr id="kongbai" style="height:40px"><td colspan="8" class="A" style="vertical-align:top">以下空白</td></tr>', endPageFill:'<tr id="kongbai" style="height:40px"><td colspan="8" class="A">接下一页</td></tr>', startPage : 1, /* totalPageSum :"${totalPageSum}", */ /* lastRowNum:"${fn:length(subjects)}" */ }); } </script>进行打印多页修改
12-05
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值