在开发过程中遇到这样一个问题:
......
<c:forEach var="district" items="${group.districtList}" varStatus="districtStatus">
     <c:forEach var="post" items="${district.postList}" varStatus="postStatus">
  <c:forEach var="mountGuardTime"items="${post.mountGuardTimeList}"varStatus="mountGuardTimeStatus">
<c:if test="${postStatus.index==0 }">
${district.name }
</c:if>
<c:if test="${postStatus.index==0&&mountGuardTimeStatus.index==0}">
<td rowspan="${district.layoutCount}">&nbsp;${district.name}</td>
<td rowspan="${district.layoutCount}">&nbsp;${district.precinct}</td>
</c:if>
<c:if test="${mountGuardTimeStatus.index==0}">
<td rowspan="${post.layoutCount}">&nbsp;${post.postTypeName}</td>
<td rowspan="${post.layoutCount}">&nbsp;${post.name}</td>
</c:if>
             ......
           </c:forEach>
      </c:forEach>
</c:forEach>
这段代码比较复杂,前后均省略了部分代码,上面红色标注部分出错,第二层循环的index,也就是postStatus.index的值没有等于0的情况,按常理来说forEach的varStatus的index都是从0开始,怎么在这样的嵌套循环中就出现不会等于0的情况,从而导致上面条件不成立,页面输出表格显示错位。
还请高人指点一下这是为什么?该如何解决?兄弟不胜感激!

解决方案 »

  1.   

    你直接打印一下:${postStatus.index}看看
      

  2.   

    不知道楼主是什么业务逻辑既然index不等于0 简单的做法 就是改成 != 0
    将if 和 else 部分的代码互换postStatus.index 这是什么的值?
      

  3.   

    你先把外层的循环都去掉。。
    只循环这一层:<c:forEach var="post" items="${district.postList}" varStatus="postStatus">看看有问题否。。一层层来嘛
      

  4.   

    业务逻辑是:上面第二个c:if里的两个输出值对应表格的每行第一个单元格的值和每行第二个单元格的值,但是会动态的进行单元格合并,因为后面还有一个时间列,如ID="1005"的成员可能会对应多个时段,这样的话该行的第一个单元格要进行合并,不过合并也是动态的。