在开发过程中遇到这样一个问题:
......
<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}"> ${district.name}</td>
<td rowspan="${district.layoutCount}"> ${district.precinct}</td>
</c:if>
<c:if test="${mountGuardTimeStatus.index==0}">
<td rowspan="${post.layoutCount}"> ${post.postTypeName}</td>
<td rowspan="${post.layoutCount}"> ${post.name}</td>
</c:if> ......
</c:forEach>
</c:forEach>
</c:forEach>
这段代码比较复杂,前后均省略了部分代码,上面红色标注部分出错,第二层循环的index,也就是postStatus.index的值没有等于0的情况,按常理来说forEach的varStatus的index都是从0开始,怎么在这样的嵌套循环中就出现不会等于0的情况,从而导致上面条件不成立,页面输出表格显示错位。
还请高人指点一下这是为什么?该如何解决?兄弟不胜感激!
......
<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}"> ${district.name}</td>
<td rowspan="${district.layoutCount}"> ${district.precinct}</td>
</c:if>
<c:if test="${mountGuardTimeStatus.index==0}">
<td rowspan="${post.layoutCount}"> ${post.postTypeName}</td>
<td rowspan="${post.layoutCount}"> ${post.name}</td>
</c:if> ......
</c:forEach>
</c:forEach>
</c:forEach>
这段代码比较复杂,前后均省略了部分代码,上面红色标注部分出错,第二层循环的index,也就是postStatus.index的值没有等于0的情况,按常理来说forEach的varStatus的index都是从0开始,怎么在这样的嵌套循环中就出现不会等于0的情况,从而导致上面条件不成立,页面输出表格显示错位。
还请高人指点一下这是为什么?该如何解决?兄弟不胜感激!
解决方案 »
- 客户端怎么用本地程序打开服务端的文件?
- 关于Struts2的标签问题
- 比较 hibernate session 是用 equal 还是 ==
- 关于hibernate的请教
- jsp怎么从sqlserver2000取出数据显示在复选筐内
- 急救啊各位大大!关于SSH中dataSource和sessionFactory代码!!
- 为什么会出错?????
- request.setAttribute()可以传递对象吗??--这个有人知道吗?
- 老鸟:struts中文显示问题,请教
- 请教:我在配置weblogic的jdbc遇到的问题
- Hibernate 和 Access 的问题
- 急.....ssh + jfreechart 怎么在jsp页面上现实
将if 和 else 部分的代码互换postStatus.index 这是什么的值?
只循环这一层:<c:forEach var="post" items="${district.postList}" varStatus="postStatus">看看有问题否。。一层层来嘛