À propos de la classe qui génère la structure des arbres d'annuaire
Ce programme a deux fichiers Test.asp, Tree.asp et quelques fichiers icônes
1. La classe d'appel Test.asp couvrant le code d'arbre est la suivante
<%@ Language=VBScript %> <html> <head> <link rel="stylesheet" href="tree.css"> <title>tree</title> </head> <!-- #include file="tree.asp" --> <% '======================================== ' BUILDING A TREE PROGRAMATICALLY '======================================= `` Cette approche serait la mieux adaptée à la construction d'arbres dynamiques en utilisant des boucles de nextes et autres. Définissez MyTree2 = New Tree MyTree2.Top = 10 Mytree2.Left = 10 Mytree2.Expandimage = "Plus.gif" Mytree2.CollapseImage = "MINUS.gif" MyTree2.leafage = "WebPage.gif" 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> "Définir 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 = "" # ""> "# #> arin" node2.createChild "<a href =" "# #> ARIN Whois Seech </a> "Node2.createChild" <a href = "" # ""> Map de fuseau horaire mondial </a> "mytree2.draw () set mytree2 = rien%> </ body> </html>2. Le code de définition de la classe Tree.asp est le suivant
<% '****************************************************************' Auteur: Jacob Gilley '' Courriel: [email protected] 'Mes conditions: vous pouvez utiliser ce contrôle dans toute façon, vous pouvez faire en sorte que je ne sois pas en appliquant en spécialisant des mots comme "Bs" Dieux ". '- Viva la Microsoft! '********************************************************************** Dim gbltreenodeCount: GBLTREENODECOUNT = 1 classe Treenode Valeur public Extensimage public CollapseMage Immording Public Property Propriété private sub class_initialize () mszname = "node" & cstr (gbltreenodeCount) gbltreenodeCount = gbltreeNODECount + 1 mbChildReninitialized = false étendue = false final sub privil Si fin sous private sub IsitchildList () définir mcolchildren = server.createObject ("scripting.dictionary") mbChildRenInitialized = True End Sub Private Sub-LoadState () If Deque InitchildList () Set CreateChild = new Treenode CreateChild.Value = SzValue CreateChild.Expandimage = Expanage CreateChild.CollapseImage = CollapseImage CreateChild.leafage = LeafImage McOlChildRen.Add McOlCHILDRES.Count + 1, CreateChild End Function Public Sub Draw () LoadState () Réponde " VBCRLF Response.Write "<Tr> <Td>" & vbcrlf Si étendu alors réponse.write "<a href =" "javascript: collapsenode ('" & mszname & "')"> <img src = "" "& collapseimage &" "" 0 "> </a>" & vbcrlf elseif not mbchildrendine src = "" "& leafImage &" "" border = 0> "& vbcrlf else réponse.write" <a href = "" javascript: expandNode ("" & mszName & "')" "> <img src =" "" & expandicage & "" "0"> </a> "& vbcrlf fini si réponse" Response.Write "<Td>" & Value & "</td> </tr>" & vbcrlf Si étendu alors réponse.write "<input type =" "Hidden" "name =" "" & mszname & "" "value =" "1" ">" & vbcrlf if MBCHILDREDIMITINATINELIATINELS puis réponse.write "<tr> <Td> </td>" & VBCrlf Answer "<tr> <Td> </td>" & VBCRLF Response.Write "<tr> <Td> </td>" & VBCRLF Response.Write "<tr> <Td> </td>" & VBCRLF "<TD>" & vbcrlf pour chaque childNode dans McOlchildren.items childnode.draw () Next réponse.write "</td>" & vbcrlf réponse.write "</tr>" & vbcrlf fini if End If Response.write "</pable>" & vbcrlf final classe de la classe de la classe publique publique publique à gauche Propriété publique privée McOlchildren Soit Absolute (bdata) Si bdata alors mszposposition = "absolu" else mszposposition = "relatif" propriété finale propriété publique obtient l'absolu () Absolute = cbool (mszposition = "Absolute") fin mnposposition = "Absolute" fin subd private sub class_terminate () mcolchildren.removeall () set mcolchildrens = rien fin de fonction subs goard createchild (szvalue) set createchild = new Treenode createchild.value = szvalue createChild.expandimage = expanage CreateChild.CollapseImage = CollapseImage CreateChild = Leafilage. 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" CreateObject ("Scripting.FileSystemObject") SET TSOBJ = FSOBJ.OPENEXTFILE (SZFILENAM 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 Ensuite, si ColNodestack.Exists (ncurrDepth) définisse alors ColNodestack.Item (ncurrDepth) = ObjWorkingNode Else Colnodestack.Add NcurrDode.CreateChild (Szline) ncurrDepth alors si nnextdepth> 1 alors nnextDepth = nnextDepth - 1 Bien qu'il ne soit pas colnodestack.exists (nnextdepth) et nnextdepth> 1 nnextdepth = nnextdepth - 1 wend set objWorkingNode = ColNodestack.Item (nnextDepth) set set objworkingNode = objWorkingNode.CreateChild (szline) nnextdepth = nnextdepth + 1 else set objWorkingNode = CreateChild (szline) fin if ncurrDepth = nnextdepth end if End if if wend tsobj.close () set tsobj = rien ne set fsobj = rien ne peut endure Sub draw () addClientScript () Response.write "<div id =" "Treectl" "style =" "Left:" & Left & "px; En haut: "& Top &" PX; Position: "& mszposition &"; ""> "& vbcrlf réponse.write" <form name = "" Treetrlfrm "" Action = "" "& request.servervariables (" script_name ") &" "" method = "" get ""> "& vbcrlf réponse.write" <table "" & vbcrlf réponse.write " VBCRLF Response.Write "<Input Type =" "Hidden" "name =" "togglenode" "value =" "" ">" & vbcrlf Response.write "</ form>" & vbcrlf Response.Write "</div>" & vbcrlf end private addClientScript ()%> <script linguisse = "javascript"> fonctionnalité d'extension de la fonction (szNoden) if (document.layers! = null) {document.trectorl.Document.TreEctRlfrm.togglenode.value = sznodeName; Document.all Document.TreEctRlfrm.Elements [SzNodeName] .Value = -1; document.trectorlfrm.Submit (); }} </ script> <% End Sub End Class%>