ASP菜单让我疯狂

时间:2009-12-05 02:05:53

标签: dynamic asp-classic menu

我正在尝试使用ASP创建一个菜单(我之前从未使用过ASP,我是一个PHP人),使用存储在数据库中的值。

基本上我想要的html布局是这样的:

<ul>
 <li>
  <ul class="sub-menu">
   <li class="sub-menu-li">Test</li>
  </ul>
 </li>
</ul>

我需要循环根菜单项rs(“AD_Level”),对于根对象,它等于0,然后在该循​​环内,绕过具有相同父ID的任何内容,例如,如果当前记录是AD_Level = 0和AD_Parent = 5然后循环所有项目AD_Parent 5和AD_Level!= 0并将值插入html,依此类推。

请帮忙!我正在努力学习一门新语言,并且在不失去理智的情况下看不到这样做的方法

修改 (从OP的评论中提取)

while not rsAdmin.eof
  sPar = rsAdmin("ad_parent"
  if rsAdmin("AD_Level")=0 then
    while not rsAdmin2.eof
      if rsAdmin2("AD_Level")<>0 and rsAdmin2("ad_parent")=sPar and rsAdmin2("AD_Sec_Level")=>2 then
        response.write rsAdmin("AD_Menu")
      end if
      rsAdmin2.movenext
    wend
  end if 
  '' # if not rsAdmin.eof then sPar=rsAdmin("AD_parent") rsAdmin.movenext
wend

这是我的代码

1 个答案:

答案 0 :(得分:0)

当然这是使用递归的一个明显的例子,只是提供下面的伪代码,因为我无法从你的代码中很好地理解你的菜单结构,所以我没有尝试将它直接放到ASP代码中:

For Each MenuItem at with Level=0
    Display the Menu Text (if applicable)
    Call GenerateSubMenu(MenuItem.ID)
Next

Function GenerateSubMenu(ID)
    For Each MenuItem with Parent=ID
        Display the Menu Text (if applicable)
        Call GenerateSubMenu(MenuItem.ID)
    Next
End Function