我查看了该站点上的先前示例,但没有任何帮助。我也对自己的困境进行了谷歌搜索,但没有成功。

我正在尝试在此处调试一些代码。我似乎可以删除最后一个逗号。有什么想法吗?

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

最佳答案

要省略最后的逗号,您可以通过这种方式测试您是否在最后一个项目上

<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

10-07 19:34
查看更多