开发者

dynamic ul with sub-levels

开发者 https://www.devze.com 2022-12-24 07:52 出处:网络
i have this recursive code <ul> <% sql=\"SELECT * FROM cats ORDER BY orderid \" rs.Open sql,Conn

i have this recursive code

<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>

inside the loop in the function i have the for the sub(s) but after each line of li it will close the ul how can i have that dynamic and to have the output like this

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

and not like this

<ul>
  <li></li>
  <li></li>
  <li>
    <ul><li></li></开发者_开发百科ul>
    <ul><li></li></ul>
    <ul><li></li></ul>
  </li>
  <li></li>
</ul>


Edited code:

<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>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号