联级菜单

function on_trview(trname,enforce)
{
 
 <%
 for(int i=0; i<topCategories.size(); i++) {
  Category c = topCategories.get(i); 
 %>
  document.all.pma_<%=c.getId()%>.style.display="none";
 <%
 }
 %>
 
 
 if (enforce=="in")
 {
     //eval里的代码当做javascript代码执行一遍
  eval("document.all.pma_"+trname+".style.display=''");
  //eval("alert()");
  //ruby on rails
 }
}

 

//获取顶级菜单
private List<Category> getTopCategories(List<Category> categories) {
  List<Category> topCategories = new ArrayList<Category>();
  for (int i = 0; i < categories.size(); i++) {
   Category c = categories.get(i);
   if (c.getGrade() == 1) {
    topCategories.add(c);
   }
  }
  return topCategories;
 }

 

//获取相应的子菜单列表

 private List<Category> getChilds(Category parent, List<Category> categories) {
  List<Category> childs = new ArrayList<Category>();
  for (int i = 0; i < categories.size(); i++) {
   Category c = categories.get(i);
   if (c.getPid() == parent.getId()) {
    childs.add(c);
   }
  }
  return childs;
 }

 

//获取子菜单

 private String getChildsStr(List<Category> childs) {
  StringBuffer buf = new StringBuffer();
  for (int i = 0; i < childs.size(); i++) {
   Category c = childs.get(i);
   buf.append(
     "<a href='ShowProducts.jsp?categoryId=" + c.getId() + "'>")
     .append(c.getName()).append("</a>").append("-");
  }
  return buf.toString();
 }

 


<table border="0" cellpadding="0" cellspacing="0" width="100%">
  <tr>
   <td align="left" background="images/topbg.gif" valign="middle"width="897">
    <table align="left" border="0" cellpadding="0" cellspacing="0"width="713">
      <tr class="style1" align="center">
       <td align="left">
       <!-- 显示第一层目录 -->
        <%
         for (int i = 0; i < topCategories.size(); i++) {
          Category c = topCategories.get(i);
        %>
        <a href="" onMouseOver="on_trview(<%=c.getId()%>,'in')">
         <!--<img src="images/00.gif" name="Image0" border="0">-->
         <span style="color: #FFFFFF"><%=c.getName()%>
         </span>
        </a>
        <%
         }
        %>
       </td>
      </tr>
    </table>
   </td>
  </tr>
  <tr>
   <td colspan="2">
    <table border="0" cellpadding="0" cellspacing="0" width="100%"> 
      <tr>
       <td background="images/topbg2.gif" height="25">
        <table style="border-collapse: collapse;" class="twoji"
         border="0" cellpadding="0" cellspacing="0" width="100%">
          <%
           for (int i = 0; i < topCategories.size(); i++) {
            Category parent = topCategories.get(i);
            List<Category> childs = getChilds(parent, categories);
          %>
          <tr id="pma_<%=parent.getId()%>" style="display: none;">
           <td style="position: relative; left: 0pt;" height="25"
            width="100%">
            &nbsp;
            <%=getChildsStr(childs)%>
           </td>
          </tr>
          <%
           }
          %>
        </table>
       </td>
      </tr>
    </table>
   </td>
  </tr>
</table>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值