dynamic ul with sub-levels
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>
精彩评论