我查看了此网站上的前几个示例,但我无法正常工作。我也搜索了我的困境,但没有成功。
我正在尝试调试一些代码。我似乎可以删掉最后一个逗号。想法?
<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 :(得分: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
答案 1 :(得分:0)
使用varStatus
<c:if test="${not deptsCounter.last}">
</c:if>