Home - Forums-.NET - FlyTreeView (ASP.NET) - Iterate the Nodes of a Tree on Client-Side

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

This forum related to following products: FlyTreeView for ASP.NET

Iterate the Nodes of a Tree on Client-Side
Link Posted: 14-Nov-2006 16:39
I thought I had done this before, but I cannot get this to work tonight. All I am trying to do is loop through the nodes of a tree and get certain properties of each node (like the id, value, text, etc.). I can't get the nodes property to work. I can't get the getNodes method to work - it always returns 1 for the number of nodes. What am I doing wrong? Here is my code: [code] <%@ Register Assembly=\"NineRays.WebControls.FlyTreeView\" Namespace=\"NineRays.WebControls\" TagPrefix=\"NineRays\" %> Untitled Page
function iterateTree() { var treeview = CFlyTreeView.getInstanceById(\"FlyTreeView1\"); if (treeview instanceof CFlyTreeView) { var nodes = treeview.getNodes() alert(nodes.length); } }
[/code]
Link Posted: 14-Nov-2006 20:53
Your code return the root nodes collection only.
Here's the modified code that gets all treeview nodes (including child nodes).





    function iterateTree()
    {
        var treeview = CFlyTreeView.getInstanceById(\"\");
        if (treeview instanceof CFlyTreeView)
        {
            var nodes = treeview.getNodes()
            alert(nodes.length);
            // get all nodes recursive using criteria function that returns true
            // for every node
            var allNodes = treeview.findAll(function(matchNode) {return true;});
            alert(allNodes.length);
        }
    }