具有子级别的动态ul

时间:2010-03-25 15:34:30

标签: html vbscript recursion

我有这个递归代码

<ul>
<%
sql="SELECT * FROM cats ORDER BY orderid " 
rs.Open sql,Conn
dim recArray
If Not rs.EOF Then
    recArray = rs.getRows()
    dim i
    for i=0 to uBound(recArray,2)
        if recArray(1,i)=0 then 
            call showMessage(i) 
        end if
    next

End If

function showMessage(index)
    %><li><%=recArray(2,index)%></li><%
    for a=0 to uBound(recArray,2)
        if recArray(1,a) = recArray(0,index) Then 
            %><ul><%
            call showMessage(a)
            %></ul><%
        end if
    next
    %></li><%
end function
%>
</ul>

在函数的循环中我有sub(s)但在每行li后它将关闭ul 我怎么能拥有这种动态并拥有像这样的输出

<ul>
  <li></li>
  <li></li>
  <li>
    <ul>
      <li></li>
      <li></li>
      <li></li>
    </ul>
  </li>
  <li></li>
</ul>

而不喜欢这个

<ul>
  <li></li>
  <li></li>
  <li>
    <ul><li></li></ul>
    <ul><li></li></ul>
    <ul><li></li></ul>
  </li>
  <li></li>
</ul>

1 个答案:

答案 0 :(得分:1)

编辑代码:

<ul>
<%
sql="SELECT * FROM cats ORDER BY orderid " 
rs.Open sql,Conn
dim recArray
If Not rs.EOF Then
    recArray = rs.getRows()
    dim i
    for i=0 to uBound(recArray,2)
        if recArray(1,i)=-1 then 
            call showMessage(i) 
        end if
    next

End If

function showMessage(index)
    %><li><%=recArray(2,index)%><%
    subs = false
    for a=0 to uBound(recArray,2)
        if recArray(1,a) = recArray(0,index) Then 
            subs = true
        end if
    next
    if subs then
        %><ul><%
        for a=0 to uBound(recArray,2)
            if recArray(1,a) = recArray(0,index) Then 
                call showMessage(a)
            end if
        next
        %></ul><%
    end if
    %></li><%
end function
%>
</ul>