asp下生成目录树结构的类
程序员文章站
2022-05-18 11:36:15
关于生成目录树结构的类
本程序有两文件test.asp 和tree.asp 还有一些图标文件
1。test.asp 调用类生成...
关于生成目录树结构的类
本程序有两文件test.asp 和tree.asp 还有一些图标文件
1。test.asp 调用类生成树 代码如下
<%@ language=vbscript %> <html> <head> <link rel="stylesheet" href="tree.css"> <title>tree</title> </head> <!-- #include file="tree.asp" --> <% '======================================== ' building a tree programatically '======================================== ' this approach would be best suited for building ' dynamic trees using for..next loops and such. set mytree2 = new tree mytree2.top = 10 mytree2.left = 10 mytree2.expandimage = "plus.gif" mytree2.collapseimage = "minus.gif" mytree2.leafimage = "webpage.gif" ' notice the indentation used to reprensent the hierarchy set node1 = mytree2.createchild("script") set subnode1 = node1.createchild("server") set secsubnode1 = subnode1.createchild("html") secsubnode1.createchild "<a href=""http://127.0.0.1/"">asp</a>" secsubnode1.createchild "<a href=""http://127.0.0.1/"">php</a>" secsubnode1.createchild "<a href=""http://127.0.0.1/"">jsp</a>" set subnode2 = node1.createchild("os") subnode2.createchild "<a href=""#"">winnt</a>" subnode2.createchild "<a href=""#"">win2000</a>" set node2 = mytree2.createchild("desktop") node2.createchild "<a href=""#"">area code lookup</a>" node2.createchild "<a href=""#"">arin based whois search</a>" node2.createchild "<a href=""#"">world time zone map</a>" mytree2.draw() set mytree2 = nothing %> </body> </html>
2。tree.asp 类的定义 代码如下
<% '****************************************************** ' author: jacob gilley ' email: avis7@airmail.net ' my terms: you can use this control in anyway you see fit ' cause i have no means to enforce any guidelines ' or bs that most developers think they can get ' you to agree to by spouting out words like ' "intellectual property" and "the code gods". ' - viva la microsoft! '****************************************************** dim gbltreenodecount:gbltreenodecount = 1 class treenode public value public expandimage public collapseimage public leafimage public expanded private mszname private mcolchildren private mbchildreninitialized public property get childcount() childcount = mcolchildren.count end property private sub class_initialize() mszname = "node" & cstr(gbltreenodecount) gbltreenodecount = gbltreenodecount + 1 mbchildreninitialized = false expanded = false end sub private sub class_terminate() if mbchildreninitialized and isobject(mcolchildren) then mcolchildren.removeall() set mcolchildren = nothing end if end sub private sub initchildlist() set mcolchildren = server.createobject("scripting.dictionary") mbchildreninitialized = true end sub private sub loadstate() if request(mszname) = "1" or request("togglenode") = mszname then expanded = true end if end sub public function createchild(szvalue) if not mbchildreninitialized then initchildlist() set createchild = new treenode createchild.value = szvalue createchild.expandimage = expandimage createchild.collapseimage = collapseimage createchild.leafimage = leafimage mcolchildren.add mcolchildren.count + 1, createchild end function public sub draw() loadstate() response.write "<table border=""0"">" & vbcrlf response.write "<tr><td>" & vbcrlf if expanded then response.write "<a href=""javascript:collapsenode('" & mszname & "')""><img src=""" & collapseimage & """ border=""0""></a>" & vbcrlf elseif not mbchildreninitialized then response.write "<img src=""" & leafimage & """ border=0>" & vbcrlf else response.write "<a href=""javascript:expandnode('" & mszname & "')""><img src=""" & expandimage & """ border=""0""></a>" & vbcrlf end if response.write "</td>" & vbcrlf response.write "<td>" & value & "</td></tr>" & vbcrlf if expanded then response.write "<input type=""hidden"" name=""" & mszname & """ value=""1"">" & vbcrlf if mbchildreninitialized then response.write "<tr><td> </td>" & vbcrlf response.write "<td>" & vbcrlf for each childnode in mcolchildren.items childnode.draw() next response.write "</td>" & vbcrlf response.write "</tr>" & vbcrlf end if end if response.write "</table>" & vbcrlf end sub end class class tree public top public left public expandimage public collapseimage public leafimage private mszposition private mcolchildren public property let absolute(bdata) if bdata then mszposition = "absolute" else mszposition = "relative" end property public property get absolute() absolute = cbool(mszposition = "absolute") end property private sub class_initialize() set mcolchildren = server.createobject("scripting.dictionary") mntop = 0 mnleft = 0 mszposition = "absolute" end sub private sub class_terminate() mcolchildren.removeall() set mcolchildren = nothing end sub public function createchild(szvalue) set createchild = new treenode createchild.value = szvalue createchild.expandimage = expandimage createchild.collapseimage = collapseimage createchild.leafimage = leafimage mcolchildren.add mcolchildren.count + 1, createchild end function public sub loadtemplate(szfilename) dim objworkingnode dim colnodestack dim fsobj, tsobj dim szline dim ncurrdepth, nnextdepth set colnodestack = server.createobject("scripting.dictionary") set fsobj = createobject("scripting.filesystemobject") set tsobj = fsobj.opentextfile(szfilename, 1) ncurrdepth = 0 while not tsobj.atendofline nnextdepth = 1 szline = tsobj.readline() if ncurrdepth = 0 then set objworkingnode = createchild(trim(szline)) ncurrdepth = 1 else while mid(szline,nnextdepth,1) = vbtab or mid(szline,nnextdepth,1) = " " nnextdepth = nnextdepth + 1 wend if nnextdepth > 1 then szline = trim(mid(szline,nnextdepth)) if szline <> "" then if nnextdepth > ncurrdepth then if colnodestack.exists(ncurrdepth) then set colnodestack.item(ncurrdepth) = objworkingnode else colnodestack.add ncurrdepth, objworkingnode end if set objworkingnode = objworkingnode.createchild(szline) ncurrdepth = ncurrdepth + 1 elseif nnextdepth <= ncurrdepth then if nnextdepth > 1 then nnextdepth = nnextdepth - 1 while not colnodestack.exists(nnextdepth) and nnextdepth > 1 nnextdepth = nnextdepth - 1 wend set objworkingnode = colnodestack.item(nnextdepth) set objworkingnode = objworkingnode.createchild(szline) nnextdepth = nnextdepth + 1 else set objworkingnode = createchild(szline) end if ncurrdepth = nnextdepth end if end if end if wend tsobj.close() set tsobj = nothing set fsobj = nothing colnodestack.removeall() set colnodestack = nothing end sub public sub draw() addclientscript() response.write "<div id=""treectrl"" style=""left: " & left & "px; top: " & top & "px; position: " & mszposition & ";"">" & vbcrlf response.write "<form name=""treectrlfrm"" action=""" & request.servervariables("script_name") & """ method=""get"">" & vbcrlf response.write "<table border=""0"">" & vbcrlf response.write "<tr><td>" & vbcrlf for each childnode in mcolchildren.items childnode.draw() next response.write "</td></tr>" & vbcrlf response.write "</table>" & vbcrlf response.write "<input type=""hidden"" name=""togglenode"" value="""">" & vbcrlf response.write "</form>" & vbcrlf response.write "</div>" & vbcrlf end sub private sub addclientscript() %> <script language="javascript"> function expandnode(sznodename) { if(document.layers != null) { document.treectrl.document.treectrlfrm.togglenode.value = sznodename; document.treectrl.document.treectrlfrm.submit(); } else { document.all["treectrlfrm"].togglenode.value = sznodename; document.all["treectrlfrm"].submit(); } } function collapsenode(sznodename) { if(document.layers != null) { document.treectrl.document.treectrlfrm.elements[sznodename].value = -1; document.treectrl.document.treectrlfrm.submit(); } else { document.treectrlfrm.elements[sznodename].value = -1; document.treectrlfrm.submit(); } } </script> <% end sub end class %>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
下一篇: ASP版实现cookies注入加速工具