0

このサイトの以前の例を確認しましたが、何も機能しませんでした。私もジレンマをグーグルで検索しましたが、成功しませんでした。

ここでいくつかのコードをデバッグしようとしています。最後のカンマを落としたように見える。考え?

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

2 に答える 2

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
于 2012-04-16T18:46:56.673 に答える
0

使用するvarStatus

<c:if test="${not deptsCounter.last}">
</c:if>
于 2012-04-16T18:27:14.643 に答える