zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    Python 魔术方法及调用方式
    Python metaclasses
    Python 实例方法,类方法和静态方法
    Python 2.x和3.x不同点
    Python 类总结
    Python 添加模块
    Python-读入json文件并进行解析及json基本操作
    linux环境下的python安装过程
    Linux系统目录结构以及简单说明
    linux下python安装
  • 原文地址:https://www.cnblogs.com/zhujiabin/p/5126714.html
Copyright © 2011-2022 走看看