Help improve this Javascript code?

Posted by Galilyou on Stack Overflow See other posts from Stack Overflow or by Galilyou
Published on 2010-05-04T12:31:22Z Indexed on 2010/05/04 12:38 UTC
Read the original article Hit count: 237

Hello SO,

In short, I'm dealing with Telerik's RadTreeView, and I want enable checking all the child nodes if the user checked the parent node. Simple enough! OK here's my code that handles OnClientNodeChecked event of the TreeView:

function UpdateAllChildren(nodes, checked) {

            var i;
            for (i = 0; i < nodes.get_count(); i++) {
                var currentNode = nodes.getNode(i);
                currentNode.set_checked(checked);
                alert("now processing: " + currentNode.get_text());
                if (currentNode.get_nodes().get_count() > 0) {
                   UpdateAllChildren(currentNode.get_nodes(), checked);                   
                }
            }
        }       

        function ClientNodeChecked(sender, eventArgs) {
            var node = eventArgs.get_node();         
            UpdateAllChildren(node.get_nodes(), node.get_checked());
        }

And here's the TreeView's markup:

<telerik:RadTreeView ID="RadTreeView1" runat="server" CheckBoxes="True" OnClientNodeChecked="ClientNodeChecked"></telerik:RadTreeView>

The tree contains quite a lot of nodes, and this is causing my targeted browser (ehm, that's IE7) to really slow down while running it. Furthermore IE7 displays an error message asking me to stop the page from running scripts as it's might make my computer not responsive (yeah, scary enough). So what do you guys propose to optimize this code?

Thanks in advance

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about telerik-radtreeview