asp下生成目录树结构的类
关于生成目录树结构的类
本程序有两文件test.asp 和tree.asp 还有一些图标文件
1。test.asp 调用类生成树 代码如下
<%@ language=vbscript %> <% '======================================== ' 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 "asp" secsubnode1.createchild "php" secsubnode1.createchild "jsp" set subnode2 = node1.createchild("os") subnode2.createchild "winnt" subnode2.createchild "win2000" set node2 = mytree2.createchild("desktop") node2.createchild "area code lookup" node2.createchild "arin based whois search" node2.createchild "world time zone map" mytree2.draw() set mytree2 = nothing %>
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 "" & vbcrlf response.write "" & vbcrlf response.write "" & vbcrlf if expanded then response.write "" & vbcrlf if mbchildreninitialized then response.write "" & vbcrlf response.write "" & vbcrlf response.write "" & vbcrlf end if end if response.write "
" & vbcrlf
response.write "" & vbcrlf
response.write "" & vbcrlf
response.write "" & vbcrlf
response.write "
" & vbcrlf
response.write "" & vbcrlf
response.write "" & vbcrlf
response.write "
" & vbcrlf
end sub
private sub addclientscript()
%>
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();
}
}
<%
end sub
end class
%> " & vbcrlf for each childnode in mcolchildren.items childnode.draw() next response.write " |