c:foreach如何嵌套循环,求指教,求优化
java类:publicclassPopedomItem{privateStringid;privateStringpid;privateStringname;priva...
java类:
public class PopedomItem {
private String id;
private String pid;
private String name;
private String checked;
private List<PopedomItem> children;
页面代码:
<c:forEach items="${items}" var="item">
<tr id="${item.id}">
<td>
<span class="folder">${item.name }</span>
</td>
<td>
--
</td>
<td>
备注说明
</td>
</tr>
<c:forEach items="${item.children}" var="it">
<tr id="${it.id}" class="child-of-${it.pid }">
<td>
<span class="<c:if test="${!empty it.children }">folder</c:if><c:if test="${empty it.children }">file</c:if>">${it.name }</span>
</td>
<td>
--
</td>
<td>
备注说明
</td>
</tr>
<c:forEach items="${it.children}" var="i">
<tr id="${i.id}" class="child-of-${i.pid }">
<td>
<span class="file">${i.name }</span>
</td>
<td>
--
</td>
<td>
备注说明
</td>
</tr>
</c:forEach>
</c:forEach>
</c:forEach> 展开
public class PopedomItem {
private String id;
private String pid;
private String name;
private String checked;
private List<PopedomItem> children;
页面代码:
<c:forEach items="${items}" var="item">
<tr id="${item.id}">
<td>
<span class="folder">${item.name }</span>
</td>
<td>
--
</td>
<td>
备注说明
</td>
</tr>
<c:forEach items="${item.children}" var="it">
<tr id="${it.id}" class="child-of-${it.pid }">
<td>
<span class="<c:if test="${!empty it.children }">folder</c:if><c:if test="${empty it.children }">file</c:if>">${it.name }</span>
</td>
<td>
--
</td>
<td>
备注说明
</td>
</tr>
<c:forEach items="${it.children}" var="i">
<tr id="${i.id}" class="child-of-${i.pid }">
<td>
<span class="file">${i.name }</span>
</td>
<td>
--
</td>
<td>
备注说明
</td>
</tr>
</c:forEach>
</c:forEach>
</c:forEach> 展开
1个回答
展开全部
<span class="<c:if test="${!empty it.children }">folder</c:if><c:if test="${empty it.children }">file</c:if>">${it.name }</span>
可以改为
<c:choose>
<c:when test="${!empty it.children }">
<c:set var="class" value="folder"/>
</c:when>
<c:otherwise>
<c:set var="class" value="file"/>
</c:otherwise>
</c:choose>
<span class="${class}">${it.name }</span>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询