EL表达式的嵌套

jayqean 2011-08-10 03:38:09

Map<String, List<Map<String, String>>> myMenu = operatorDao.getMyMenus(user);
Map<String, String> menuMap = new HashMap<String, String>();
menuMap.put("1","客户账号管理");
menuMap.put("2","查询统计");
menuMap.put("3","资金管理");
menuMap.put("4","代理商管理");
menuMap.put("5","操作员管理");
menuMap.put("6","任务管理");
menuMap.put("7","菜单管理");
req.setAttribute("menuMap", menuMap);
req.setAttribute("myMenu", myMenu);



<c:forEach var="map" items="${menuMap}" varStatus="status">
<table cellpadding=0 cellspacing=0 width="96%" align=center>
<tr>
<td height=25 class=menu_title id=menuTitle1 onclick="showsubmenu(${status.count})"> ${map.value}</td>
</tr>
<tr>
<td style="display:none" id='submenu${status.count}'>
<table cellpadding=0 cellspacing=0 width="100%" bgcolor="#C2E0EC" class=sec_menu>
<tr>
<td height=10></td>
</tr>
<c:forEach var="childMap" items="${myMenu['status.count']}">
<tr>
<td height=20>
<img src=<%=request.getContextPath()%>/images/bullet.gif border=0><a href="<%=request.getContextPath()%>${childMap['url']}">${childMap['show_name']}</a>
</td>
</tr>
</c:forEach>
</table>
</td>
</tr>
</table>
</c:forEach>

请教下,好久没弄WEB了,上面EL表达式 第二个foreach显示不出内容
myMenu是个map 然后第二个foreach就是想利用${status.count}作键,取出List<Map<String, String>>进行迭代
可惜出不来,
如果写死,${myMenu['1']} 是可以迭代出来东西.
...全文
486 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
千锤_百炼 2012-01-02
  • 打赏
  • 举报
回复
顶楼主,我也碰见跟你一样 的问题!楼主的办法可行,支持!
傻傻的傻傻傻 2011-08-10
  • 打赏
  • 举报
回复
遍历myMenu.key根据key就能拿到value

另外el确实不能嵌套
kcs1991 2011-08-10
  • 打赏
  • 举报
回复
应该map的值应该只是可以是myMenu.key值和myMenu.value值可以迭代的吧!
jayqean 2011-08-10
  • 打赏
  • 举报
回复

<c:forEach var="map" items="${menuMap}" varStatus="status">
<table cellpadding=0 cellspacing=0 width="96%" align=center>
<tr>
<td height=25 class=menu_title id=menuTitle1 onclick="showsubmenu(${status.count})"> ${map.value}</td>
</tr>
<tr>
<td style="display:none" id='submenu${status.count}'>
<table cellpadding=0 cellspacing=0 width="100%" bgcolor="#C2E0EC" class=sec_menu>
<tr>
<td height=10></td>
</tr>
<c:forEach var="mk" items="${myMenu}">
<c:if test="${mk.key == status.count}">
<c:forEach var="childMap" items="${mk.value}">
<tr>
<td height=20>
<img src=${pageContext.request.contextPath}/images/bullet.gif border=0><a href="${pageContext.request.contextPath}${childMap['url']}">${childMap['show_name']}</a>
</td>
</tr>
</c:forEach>
</c:if>
</c:forEach>
</table>
</td>
</tr>
</table>
</c:forEach>

先遍历map,再取键值 判断键值是否和父菜单 符合
符合的情况下 再次遍历 map的值
jayqean 2011-08-10
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 trocp 的回复:]
${myMenu[status.count]}
[/Quote]
你这种我试过了不行的
oO临时工Oo 2011-08-10
  • 打赏
  • 举报
回复
${myMenu[status.count]}
zl3450341 2011-08-10
  • 打赏
  • 举报
回复
解决了结账吧。。
jayqean 2011-08-10
  • 打赏
  • 举报
回复
我猜问题是''的问题,里面写值是不是当作字符处理
自己绕开了这问题,解决了.

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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