2012-04-16 19 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