快捷搜索:

生成目录树结构的类

本法度榜样有两文件test.asp 和tree.asp 还有一些图标文件

1。test.asp 调用类天生树 代码如下

2。tree.asp 类的定义 代码如下

" & vbCrLf

Response.Write "

" & vbCrLf

If Expanded Then

Response.Write "" & vbCrLf

ElseIf Not mbChildrenInitialized Then

Response.Write "" & vbCrLf

Else

Response.Write "" & vbCrLf

End If

Response.Write "" & vbCrLf

Response.Write "

" & Value & "" & vbCrLf

If Expanded Then

Response.Write "" & vbCrLf

If mbChildrenInitialized Then

Response.Write "

" & vbCrLf

Response.Write "

" & vbCrLf

For Each ChildNode In mcolChildren.Items

ChildNode.Draw()

Next

Response.Write "" & vbCrLf

Response.Write "" & vbCrLf

End If

End If

Response.Write "" & 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 szLinenCurrDepth 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 nNextDepth1 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 "

" & vbCrLf

Response.Write "" & vbCrLf

Response.Write "" & vbCrLf

Response.Write "

" & vbCrLf

For Each ChildNode In mcolChildren.Items

ChildNode.Draw()

Next

Response.Write "" & vbCrLf

Response.Write "" & vbCrLf

Response.Write "" & vbCrLf

Response.Write "" & vbCrLf

Response.Write "

" & vbCrLf

End Sub

Private Sub AddClientScript()

%>

您可能还会对下面的文章感兴趣: