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
%>
演示地址:http://www.cnaspol.com/templatetree/test.asp
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器