c:foreach如何嵌套循環,求指教,求優化


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>

提問者采納

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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM