返回 NavigationNodes 集合对象,该对象代表当前导航节点的子树中所有节点的集合。节点的子树定义为与父节点相邻或附加于父节点,并在树层次结构中显示在父节点之下的所有节点。
expression.SubTree
expression 必选。返回 NavigationNode 对象的表达式。
下列示例提示用户输入当前站点中的导航节点的名称,并返回该特定节点的子树。如果找到该节点,则将其 label 属性值添加到一个 String 类型的值中,其中包含父节点的子树中所有节点的名称。存储在变量 strSubNodes 中的这个 String 值会显示给用户。如果站点中没有找到该节点,则向用户显示一条消息。
Sub DisplaySubTree()
'Returns the subtree of a given node
Dim objApp As FrontPage.Application
Dim objNavNode As NavigationNode
Dim objNavNodes As NavigationNodes
Dim objSubTree As NavigationNodes
Dim objSubNode As NavigationNode
Dim strAns As String 'User input
Dim blnFound As Boolean 'Boolean found flag
Dim intCount As Integer 'Integer counter
Dim strSubNodes As String 'Names of all sub nodes
blnFound = False
intCount = 0
Set objApp = FrontPage.Application
'Create a reference to the NavigationNodes collection
Set objNavNodes = objApp.ActiveWeb.AllNavigationNodes
'Prompt the user to enter the name of the node
strAns = InputBox("Enter the name of the node for which " & _
" you want to view the subtree.")
'While the node is not found and there are more nodes in the tree
Do While (Not blnFound = True) And (intCount <= objNavNodes.Count - 1)
'Compare user input with node label
If Trim(strAns) = objNavNodes.Item(intCount).Label Then
'If found, return node
Set objNavNode = objNavNodes.Item(intCount)
'Set found flag to true
blnFound = True
Else
'Otherwise increase counter, keep checking
intCount = intCount + 1
End If
Loop
If blnFound = True Then
Set objSubTree = objNavNode.SubTree
For Each objSubNode In objSubTree
'If the string is empty or has not yet been set
If strSubNodes = "" Then
strSubNodes = strSubNodes & objSubNode.Label
Else
'otherwise add next node lable to string
strSubNodes = strSubNodes & ", " & vbCr & objSubNode.Label
End If
Next objSubNode
'Display names of all nodes in subtree
MsgBox "The nodes found in the subtree of " & objNavNode.Label & " are: " _
& vbCr & vbCr & strSubNodes & "."
Else
'If not found, display message to user
MsgBox "The navigation node " & strAns & " was not found."
End If
End Sub