2012-04-16 21 views
0

我回顾了本网站上的以前的例子,我无法获得任何工作。我也搜索了我的困境,但没有成功。在JSTL中省略最后的逗号<c:out>

我想在这里调试一些代码。我似乎可以放弃最后一个逗号。思考?

<c:forEach items="${userDeptList}" var="userDeptVar" varStatus="userDeptCounter" > 
    <c:if test="${contactsVar.userId==userDeptVar.userID}"> 
     <c:forEach items="${deptPtypeList}" var="deptsVar" varStatus="deptsCounter" > 
     <c:if test="${deptsVar.ptypeID==userDeptVar.deptID}"> 
      <c:out value="${deptsVar.type}" escapeXml="false"></c:out> 
      <c:out value="," escapeXml="false"></c:out> 
     </c:if>  
     </c:forEach>       
    </c:if>     
</c:forEach> 
+0

你想在这里做什么?输入?输出?你读过什么样的例子? – evanwong 2012-04-16 18:26:29

+0

谢谢JJ,最后一个部门 – rlegs 2012-04-16 18:59:57

回答

0

使用varStatus

<c:if test="${not deptsCounter.last}"> 
</c:if> 
+0

后我仍然收到一个逗号。我试过这个,它不工作。 – rlegs 2012-04-16 18:47:09

+0

能否详细说明不能正常工作请 – 2012-04-16 18:48:23

+0

最后一个部门 – rlegs 2012-04-16 19:02:35

1

要省略最后一个逗号,你可以测试,如果你是在最后一个项目这样

<c:forEach items="${userDeptList}" var="userDeptVar" varStatus="userDeptCounter" > 
    <c:if test="${contactsVar.userId==userDeptVar.userID}"> 
     <c:forEach items="${deptPtypeList}" var="deptsVar" varStatus="deptsCounter" > 
     <c:if test="${deptsVar.ptypeID==userDeptVar.deptID}"> 
      <c:out value="${deptsVar.type}" escapeXml="false"></c:out> 
      <c:if test="${not userDeptCounter.last}> 
       <c:out value="," escapeXml="false"></c:out> 
      </c:if> 
     </c:if>  
     </c:forEach>       
    </c:if>     
</c:forEach> 

这里所有varStatus属性的列表

current The item (from the collection) for the current round of iteration 
index  The zero-based index for the current round of iteration 
count  The one-based count for the current round of iteration 
first  Flag indicating whether the current round is the first pass through the iteration 
last  Flag indicating whether the current round is the last pass through the iteration 
begin  The value of the begin attribute 
end  The value of the end attribute 
step  The value of the step attribute