急求:关于jstl标签forEach嵌套循环问题

machelli 2011-07-14 10:47:45
<c:forEach var="department" items="${departmentList}" varStatus="departmentStatus">
<c:forEach var="group" items="${department.groupList}" varStatus="groupStatus">
<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">
<tr>

<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>
<td> ${mountGuardTime}</td>
<td id="policeName_${post.id}_${mountGuardTimeStatus.index}"><c:forEach var="policeLayoutDetail" items="${layout.policeLayoutDetailList}"><c:if test="${policeLayoutDetail.postID==post.id&&policeLayoutDetail.mountGuardTime==mountGuardTime}">${policeLayoutDetail.policeName} </c:if></c:forEach> </td>
<td>
<input type="hidden" id="policeID_${post.id}_${mountGuardTimeStatus.index}" name="policeID_${post.id}_${mountGuardTimeStatus.index}" value="<c:forEach var="policeLayoutDetail" items="${layout.policeLayoutDetailList}"><c:if test="${policeLayoutDetail.postID==post.id&&policeLayoutDetail.mountGuardTime==mountGuardTime}">${policeLayoutDetail.policeID}|</c:if></c:forEach>"/><a href="#" onClick='javascript:showPoliceList("${post.id}_${mountGuardTimeStatus.index}");' ><img src="resource/image/images/edit.gif" alt="指定信息"/></a>
</td>
</tr>
</c:forEach>
</c:forEach>
</c:forEach>
</c:forEach>
</c:forEach>
通过如上循环在页面上动态生成表格并动态输出表格项中的值。
问题是:这个判断<c:if test="${postStatus.index==0&&mountGuardTimeStatus.index==0}">......</c:if>
是要在页面里输出合并行,其条件是上层循环的index与内层循环的index都等于零的时候,就会输出合并单元格,按照常理index都会从零开始,可是现在postStatus.index不是从零开始,也就是说没有0,0组合的情况,即条件不满足,导致页面显示有误,不能输出合并单元格。请各位高人指点,这是怎么回事,为什么外层循环的index值不是从零开始?谢谢各位仁兄了!
...全文
899 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
bianhei000 2011-07-14
  • 打赏
  • 举报
回复
五层循环。。。。。还是前台。。。。
这写的什么程序啊 分开一块快的不行么
老张-AI 2011-07-14
  • 打赏
  • 举报
回复
楼主能排下版不?

另外这么复杂的逻辑,难道后台不能处理好了再传回前台?? 前台尽量不要搞太复杂的逻辑
machelli 2011-07-14
  • 打赏
  • 举报
回复
在最内层输出postStatus.index,和mountGuardTimeStatus.index的值分别是这样几组数据:2,0 2,1 2,2 3,0 3,1 3,2 0,0 0,1 0,2,按照数据库查出的数据,应该有三行,九组数据每三个一合并,可是现在只有最后三个进行了合并,其他6个没有进行合并,很难解决这个问题啊!请高人指点
这个FOREACH循环问题到底出在什么地方?
diaoerdiaoerdiaoer 2011-07-14
  • 打赏
  • 举报
回复
调试一下呗 或者alert一下值出来看一下不就知道什么原因了吗 关键是慢慢来 不要急
machelli 2011-07-14
  • 打赏
  • 举报
回复
查询列表的表格是通过动态输出的,单元格的合并也是动态的,表格中的数据来至多张表,而且这些数据具有类似树结构的组织方式,因此必须会用到多重循环,这是用户已经确认的需求,无可争辩。我已经把如上各层循环的index输出
是如下9组:2,2,0,2,0 2,2,0,2,1 2,2,0,2,2 2,2,0,3,0 2,2,0,3,1 2,2,0,3,2 2,2,2,0,0 2,2,2,0,1 2,2,2,0,2

表格的数据显示是这一个:所在区,所辖区域,岗位,岗位类型,时间段
结构如下:每个区下设有多个岗位,以及岗位类型,而每个岗位对应有多个时间段,如果A区下设有三个岗位,那么第一个单元格是3行合并,动态设置rowspan等于3,这个值是在后台经过一系列计算的,在传入前台;而若A区下的每个岗位又对应有3个时间段,那么该区下的该岗位所在的单元格应进行单元格合并,动态设置rowspan等于3,
表格数据显示如下形式:
所在区 所辖区域 岗位 岗位类型 时间段
A nnn 岗位1 a 9:00~12:00
13:00~15:00
16:00~18:00
岗位2 b 9:00~12:00
13:00~15:00
16:00~18:00

B aaa 岗位1 s 9:00~12:00
13:00~15:00
岗位2 n 13:00~15:00

51,408

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧