Partager via


getChildren Method

Retrieves an array of TreeNode elements from its parent object.

Syntax

oChildNodes = object.getChildren()

Return Value

An array of TreeNode elements. The length of the array object is zero if no children exist.

Example

The following example demonstrates how to retrieve an array of TreeNodes.

<HTML XMLNS:myTree>
 
<?IMPORT NameSpace="myTree" Implementation="treeview.htc"/>
<HEAD>
<TITLE></TITLE> 
<SCRIPT language="jscript">
// Walk through the tree.
function walkChildren(arrayChildren){
    var currentChild;
    for (var i = 0; i < arrayChildren.length; i++){
        currentChild = arrayChildren[i];
        childrenDIV.innerText += "[" + currentChild.getAttribute("Text") + "]";
        walkChildren(currentChild.getChildren());
   }
} 
</SCRIPT>
</HEAD>

<BODY>
<myTree:TREEVIEW id="treeview1" systemimagespath="treeimages"
    selectexpands=true >
  
  <myTree:TREENODE text="root1" expanded=true checkbox=true >
      <myTree:TREENODE text="document1" checkbox=true />
      <myTree:TREENODE text="folder1" expanded=true checkbox=true >
           <myTree:TREENODE text="document2" checkbox=true />
      </myTree:TREENODE>
      <myTree:TREENODE text="document3" checkbox=true />
  </myTree:TREENODE>
  
  <myTree:TREENODE text="root2" checkbox=true />
</myTree:TREEVIEW>
 
<BR>
<DIV id=childrenDIV></DIV>
<BR>

<BUTTON onclick="walkChildren(treeview1.getChildren()); ">Get children</BUTTON>
</BODY>
</HTML>

Code example: https://samples.msdn.microsoft.com/workshop/samples/webcontrols/treeview/getChildren.htm

Applies To

TREENODE, TREEVIEW

See Also

About the TreeView WebControl, TreeNode