Html 具有子级别的动态ul
我有这个递归代码Html 具有子级别的动态ul,html,vbscript,recursion,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 showMessa
<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>
-
而不是像这样
<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>
-
编辑的代码:
<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>
你能给我一些示例数据吗?我有9只猫,在数据库中我有id、fid、名称和医嘱id fid是父亲id-如果没有父亲,它会得到(-1)我从你给我的代码中得到的是- /ul>当然,最有可能是li里面有文本,因为你把它改成了getRows,然后用for循环遍历它,所以它只生成了li。它永远不会通过if,因为现在没有任何东西可以第一次比较它,它是无辜的。。。只有ul从不传递条件:recArray(1,a)=recArray(0,索引)如果我将其更改为recArray(1,a)=-1,则为传递,但随后我得到错误类型:Microsoft VBScript运行时(0x800A0007)内存不足:for b=0到uBound(recArray,2)行中的“createobject”嗯,是否将根从0更改为-1?因为你的代码也不应该工作。。。我将更新我的代码。不使用-1你能给我一个递归代码表,它将检查记录-并将它们设置为UL list with childrens吗?