熬了一宿研究一个小功能,本来指望的朋友帮我看看,结果还是自己动手解决了。
最早写了一个标签,可以调出产品模块(自定义模块建立的)的所有目录并形成菜单,先贴上代码,有空再放演示了
function productstreelist(l1,l2)
dim rs,I1,data,i,nbsp
if cstr(l1)="0" then
I1=I1&"<div id=""right-menu""><ul id=""nav"">"
end if
for i=1 to l2
nbsp=nbsp&" "
next
set rs=conn.execute("select listid,listname,listpath from king__products_list where listid1="&l1&" order by listorder asc,listid")
if not rs.eof and not rs.bof then
data=rs.getrows()
for i=0 to ubound(data,2)
I1=I1&"<li><a href="""&data(2,i)&""">"&data(1,i)&"</a></li>"
if conn.execute("select count(listid) from king__products_list where listid1="&data(0,i)&";")(0)>0 then
I1=I1&"<ul>"&productstreelist(data(0,i),l2+1)&"</ul>"
end if
next
end if
rs.close
set rs=nothing
if cstr(l1)="0" then
I1=I1&"<ul></div>"
end if
productstreelist=I1
end function
这段代码有一个问题是没有判断哪一级是目录底层,所以有不好用的地方。于是写了下面两段
function king_tag_products_alllist(tag,invalue)
dim jshtm,jslistid,listid,I1
if len(king.getlabel(tag,"listid"))>0 then
jslistid=king.getlabel(tag,"listid")
else
jslistid=king.getvalue(invalue,"listid")
end if
jshtm=king_tag_products_alllistpart(jslistid)
I1=I1&jshtm
king_tag_products_alllist=I1
end function
function king_tag_products_alllistpart(l1)
dim rs,I1,i,ChildCount,FolderType,FolderName
set rs=conn.execute("Select listid,listname,listpath,listid1 From king__products_list where listid1='"&l1&"' order by listorder asc,listid" )
if rs.BOF and rs.EOF Then
I1=I1&"暂无分类!"
end if
i=1
while not rs.eof
ChildCount=conn.execute("select count(listid) from king__products_list where listid1="&rs("listid")&";")(0)
if ChildCount=0 then
FolderType="<b style=""color:#ED2224;"">—</b> "
else
FolderType="<b onclick=""showClassList("&rs("listid")&");"" style=""cursor:pointer; color:#ED2224;"">+</b> "
end if
FolderName=rs("listname")
I1=I1&"<div>"&FolderType&"<a href=""/"&rs("listpath")&""">"&FolderName&"</a></div>"
if ChildCount>0 then
I1=I1&"<div id=""info_one_"&rs("listid")&""" style=""DISPLAY: none;"">"&king_tag_products_alllistpart(rs("listid"))&"</div>"
end if
rs.movenext
i=i+1
wend
rs.close
set rs=nothing
king_tag_products_alllistpart=I1
end function
这两段可以实现前台用{king:productsalllist /} 这样的标签就可以调用出当前这个栏目下的所有子栏目。也可以用{king:productsalllist listid="0"/}将全站菜单调出,或{king:productsalllist listid="1"/}调用某一栏目下的所有子栏目, 因为需要一点css样式的判断才能形成目录树支持,所以在代码里就直接加上了。
困了,等有时间再来贴介绍了。