根据模板文件建立动态目录树结构的类
发表于:2007-06-30来源:作者:点击数:
标签:
根据模板文件建立动态目录树结构的类:建议入精华备查,有演示br 演示地址:http://www.cnaspol.com/myasp/mmtree/treesample.aspbr 本程序包括三文件和相关的图片文件,包括test.asp,tree.asp,mytree.txt组成br test.asp 引用类文件和模板文件br lt;%@ Langu
根据模板文件建立动态目录树结构的类:建议入精华备查,有演示<br>
演示地址:http://www.cnaspol.com/myasp/mmtree/treesample.asp<br>
本程序包括三文件和相关的图片文件,包括test.asp,tree.asp,mytree.txt组成<br>
test.asp 引用类文件和模板文件<br>
<%@ Language=
VBScript %><br>
<!-- #include file="tree.asp" --><br>
<%<br>
@#========================================<br>
@#BUILDING A TREE FROM A TEMPLATE FILE<br>
@#========================================<br>
<br>
Set MyTree1 = New Tree<br>
MyTree1.Top = 10<br>
MyTree1.Left = 10<br>
MyTree1.ExpandImage = "plus.gif"<br>
MyTree1.CollapseImage = "minus.gif"<br>
MyTree1.LeafImage = "webpage.gif"<br>
<br>
MyTree1.LoadTemplate Server.MapPath("mytree.txt")<br>
<br>
MyTree1.Draw()<br>
<br>
Set MyTree1 = Nothing<br>
<br>
%><br>
<br>
</BODY><br>
</HTML><br>
<br>
<br>
mytree.txt 树形结构模板文件<br>
<br>
Cisco<br>
Cisco Links #1<br>
<A HREF="#">Adjusting IP MTU, TCP MSS, and PMTUD on Windows and Sun Systems (by Cisco)</A><br>
<A HREF="#">Cisco Command Documentation</A><br>
<A HREF="#">Cisco@#s Collection</A><br>
Cisco Links #2<br>
<A HREF="#">DFW Cisco Users Group</A><br>
<A HREF="#">Internet Protocol Journal (by Cisco)</A><br>
asp #2<br>
asp #2<br>
<A HREF="#">
vb</A><br>
<A HREF="#">asp</A><br>
Desktop<br>
Cisco Links #3<br>
<A HREF="#">Area Code Lookup</A><br>
<A HREF="#">Arin Based Whois Search</A><br>
<A HREF="#">World Time Zone Map</A><br>
Cisco Links #4<br>
<A HREF="#">Area Code Lookup</A><br>
<A HREF="#">Arin Based Whois Search</A><br>
<A HREF="#">World Time Zone Map</A><br>
<A HREF="#">World Time Zone Map</A><br>
Internet<br>
<A HREF="#">Index of Traceroute Web Servers</A><br>
<A HREF="#">Internet Health Report (Daze Networks, Inc.</A><br>
<A HREF="#">Internet Protocol Journal (by Cisco)</A><br>
<A HREF="#">Internet Traffic Report</A><br>
<A HREF="#">InterNIC Network Solutions Homepage</A><br>
<A HREF="#">IP 101: All About IP Addressing by CMP Net</A><br>
Network<br>
<A HREF="#">Digex Network Services Group</A><br>
<A HREF="#">Network Computing Online</A><br>
<A HREF="#">Network Computing Online: Technology Center</A><br>
<A HREF="#">Network Training Web Site (by InterOperability Lab)</A><br>
<A HREF="#">Networking Primer (by Bay Networks)</A><br>
<A HREF="#">Subnetting (by Network Computing Online)</A><br>
Software Support<br>
<A HREF="#">Sym
antec Security Alerts</A><br>
Technology<br>
<A HREF="#">Technology Dictionary (by PCWebopaedia)</A><br>
<A HREF="#">Technology Dictionary (by whatis?com)</A><br>
<A HREF="#">Technology Topics (by N.E.T.)</A><br>
<A HREF="#">Tracert</A><br>
<A HREF="#">Understanding I.P. Addressing (by 3Com)</A><br>
Trading<br>
<A HREF="#">Keynote Web Broker Trading Index</A> <br>
<A HREF="#">NASDAQ</A><br>
Training<br>
<A HREF="#">RFC Index (Ohio State University)</A><br>
<A HREF="#">Vi/Ex Editor (by CMP Net)</A><br>
<br>
<br>
<br>
<br>
tree.asp 处理树形结构的vbsclass类(关键)<br>
<br>
<%<br>
Dim gblTreeNodeCount:gblTreeNodeCount = 1<br>
Class TreeNode<br>
Public Value<br>
Public ExpandImage<br>
Public CollapseImage<br>
Public LeafImage<br>
Public Expanded<br>
Private mszName<br>
Private mcolChildren<br>
Private mbChildrenInitialized<br>
<br>
Public Property Get ChildCount()<br>
ChildCount = mcolChildren.Count<br>
End Property<br>
<br>
Private Sub Class_Initialize()<br>
mszName = "node" & CStr(gblTreeNodeCount)<br>
gblTreeNodeCount = gblTreeNodeCount + 1<br>
<br>
mbChildrenInitialized = False<br>
Expanded = False<br>
End Sub <br>
<br>
Private Sub Class_Terminate()<br>
If mbChildrenInitialized And IsObject(mcolChildren) Then<br>
mcolChildren.RemoveAll()<br>
Set mcolChildren = Nothing<br>
End If<br>
End Sub<br>
<br>
Private Sub InitChildList()<br>
Set mcolChildren = Server.CreateObject("Scripting.Dictionary")<br>
mbChildrenInitialized = True<br>
End Sub<br>
<br>
Private Sub LoadState()<br>
If Request(mszName) = "1" Or Request("togglenode") = mszName Then<br>
Expanded = True<br>
End If<br>
End Sub<br>
<br>
Public Function CreateChild(szValue)<br>
<br>
If Not mbChildrenInitialized Then InitChildList()<br>
<br>
Set CreateChild = New TreeNode<br>
CreateChild.Value = szValue<br>
CreateChild.ExpandImage = ExpandImage<br>
CreateChild.CollapseImage = CollapseImage<br>
CreateChild.LeafImage = LeafImage<br>
<br>
mcolChildren.Add mcolChildren.Count + 1, CreateChild<br>
<br>
End Function<br>
<br>
Public Sub Draw()<br>
<br>
LoadState()<br>
<br>
Response.Write "<table border=""0"">" & vbCrLf<br>
Response.Write "<tr><
td>" & vbCrLf<br>
<br>
If Expanded Then<br>
Response.Write "<a href=""
javascript:collapseNode(@#" & mszName & "@#)""><img src=""" & CollapseImage & """ border=""0""></a>" & vbCrLf<br>
ElseIf Not mbChildrenInitialized Then<br>
Response.Write "<img src=""" & LeafImage & """ border=0>" & vbCrLf<br>
Else<br>
Response.Write "<a href=""javascript:expandNode(@#" & mszName & "@#)""><img src=""" & ExpandImage & """ border=""0""></a>" & vbCrLf<br>
End If<br>
<br>
Response.Write "</td>" & vbCrLf<br>
Response.Write "<td>" & Value & "</td></tr>" & vbCrLf<br>
<br>
If Expanded Then<br>
Response.Write "<input type=""hidden"" name=""" & mszName & """ value=""1"">" & vbCrLf<br>
<br>
If mbChildrenInitialized Then<br>
Response.Write "<tr><td> </td>" & vbCrLf<br>
Response.Write "<td>" & vbCrLf<br>
<br>
For Each ChildNode In mcolChildren.Items<br>
ChildNode.Draw()<br>
Next<br>
<br>
Response.Write "</td>" & vbCrLf<br>
Response.Write "</tr>" & vbCrLf<br>
End If<br>
End If<br>
<br>
Response.Write "</table>" & vbCrLf<br>
<br>
End Sub<br>
<br>
End Class<br>
<br>
<br>
Class Tree<br>
<br>
Public Top<br>
Public Left<br>
Public ExpandImage<br>
Public CollapseImage<br>
Public LeafImage<br>
Private mszPosition<br>
Private mcolChildren<br>
<br>
Public Property Let Absolute(bData)<br>
If bData Then mszPosition = "absolute" Else mszPosition = "relative"<br>
End Property<br>
<br>
Public Property Get Absolute()<br>
Absolute = CBool(mszPosition = "absolute")<br>
End Property<br>
<br>
Private Sub Class_Initialize()<br>
Set mcolChildren = Server.CreateObject("Scripting.Dictionary")<br>
mnTop = 0<br>
mnLeft = 0<br>
mszPosition = "absolute"<br>
End Sub <br>
<br>
Private Sub Class_Terminate()<br>
mcolChildren.RemoveAll()<br>
Set mcolChildren = Nothing<br>
End Sub<br>
<br>
Public Function CreateChild(szValue)<br>
<br>
Set CreateChild = New TreeNode<br>
<br>
CreateChild.Value = szValue<br>
CreateChild.ExpandImage = ExpandImage<br>
CreateChild.CollapseImage = CollapseImage<br>
CreateChild.LeafImage = LeafImage<br>
<br>
mcolChildren.Add mcolChildren.Count + 1, CreateChild<br>
<br>
End Function<br>
<br>
Public Sub LoadTemplate(szFileName)<br>
Dim objWorkingNode<br>
Dim colNodeStack<br>
Dim fsObj, tsObj<br>
Dim szLine<br>
Dim nCurrDepth, nNextDepth<br>
<br>
Set colNodeStack = Server.CreateObject("Scripting.Dictionary")<br>
Set fsObj = CreateObject("Scripting.FileSystemObject")<br>
Set tsObj = fsObj.OpenTextFile(szFileName, 1)<br>
<br>
nCurrDepth = 0<br>
While Not tsObj.AtEndOfLine<br>
nNextDepth = 1<br>
szLine = tsObj.ReadLine()<br>
<br>
If nCurrDepth = 0 Then<br>
Set objWorkingNode = CreateChild(Trim(szLine))<br>
nCurrDepth = 1<br>
Else<br>
While Mid(szLine,nNextDepth,1) = vbTab Or Mid(szLine,nNextDepth,1) = " "<br>
nNextDepth = nNextDepth + 1<br>
WEnd<br>
<br>
If nNextDepth > 1 Then szLine = Trim(Mid(szLine,nNextDepth))<br>
<br>
If szLine <> "" Then<br>
If nNextDepth > nCurrDepth Then<br>
If colNodeStack.Exists(nCurrDepth) Then<br>
Set colNodeStack.Item(nCurrDepth) = objWorkingNode<br>
Else<br>
colNodeStack.Add nCurrDepth, objWorkingNode<br>
End If<br>
<br>
Set objWorkingNode = objWorkingNode.CreateChild(szLine)<br>
<br>
nCurrDepth = nCurrDepth + 1<br>
ElseIf nNextDepth <= nCurrDepth Then<br>
<br>
If nNextDepth > 1 Then <br>
<br>
nNextDepth = nNextDepth - 1<br>
While Not colNodeStack.Exists(nNextDepth) And nNextDepth > 1<br>
nNextDepth = nNextDepth - 1<br>
WEnd<br>
<br>
Set objWorkingNode = colNodeStack.Item(nNextDepth)<br>
Set objWorkingNode = objWorkingNode.CreateChild(szLine)<br>
<br>
nNextDepth = nNextDepth + 1<br>
Else<br>
Set objWorkingNode = CreateChild(szLine)<br>
End If<br>
<br>
nCurrDepth = nNextDepth<br>
End If<br>
End If<br>
<br>
End If<br>
WEnd<br>
<br>
tsObj.Close()<br>
Set tsObj = Nothing <br>
Set fsObj = Nothing<br>
<br>
colNodeStack.RemoveAll()<br>
Set colNodeStack = Nothing<br>
<br>
End Sub<br>
<br>
<br>
Public Sub Draw()<br>
<br>
AddClientScript()<br>
<br>
Response.Write "<div id=""treectrl"" style=""left: " & Left & "px; top: " & Top & "px; position: " & mszPosition & ";"">" & vbCrLf<br>
Response.Write "<form name=""treectrlfrm"" action=""" & Request.ServerVariables("SCRIPT_NAME") & """ method=""get"">" & vbCrLf<br>
Response.Write "<table border=""0"">" & vbCrLf<br>
Response.Write "<tr><td>" & vbCrLf<br>
<br>
For Each ChildNode In mcolChildren.Items<br>
ChildNode.Draw()<br>
Next<br>
<br>
Response.Write "</td></tr>" & vbCrLf<br>
Response.Write "</table>" & vbCrLf<br>
<br>
Response.Write "<input type=""hidden"" name=""togglenode"" value="""">" & vbCrLf<br>
Response.Write "</form>" & vbCrLf<br>
Response.Write "</div>" & vbCrLf<br>
<br>
End Sub<br>
<br>
Private Sub AddClientScript()<br>
%><br>
<script language="
JavaScript"><br>
<br>
function expandNode(szNodeName)<br>
{<br>
if(document.layers != null) {<br>
document.treectrl.document.treectrlfrm.togglenode.value = szNodeName;<br>
document.treectrl.document.treectrlfrm.submit();<br>
}<br>
else {<br>
document.all["treectrlfrm"].togglenode.value = szNodeName;<br>
document.all["treectrlfrm"].submit();<br>
}<br>
}<br>
<br>
function collapseNode(szNodeName)<br>
{<br>
if(document.layers != null) {<br>
document.treectrl.document.treectrlfrm.elements[szNodeName].value = -1;<br>
document.treectrl.document.treectrlfrm.submit();<br>
}<br>
else {<br>
document.treectrlfrm.elements[szNodeName].value = -1;<br>
document.treectrlfrm.submit();<br>
}<br>
}<br>
<br>
</script><br>
<% <br>
End Sub<br>
<br>
End Class<br>
%><br>
<br>
原文转自:http://www.ltesting.net