This is a migrated thread and some comments may be shown as answers.

Adding children nodes to a RadTreeNodeCollection of a RadTreeNode in JavaScript

2 Answers 194 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Justin
Top achievements
Rank 1
Justin asked on 27 Aug 2009, 05:16 PM
I have to add in children nodes to a RadTreeNode in JavaScript. The Node currently doesn't have any children. We cannot post back or do an AJAX call to get the additonal data (performance isn't good enough, and besides, we have the data locally in JavaScript anyway). However, when there isn't already some children nodes in a RadTreeNode, we get a JavaScript error "get_childListElement(...) is null or undefined" when calling the following code:

radNode.get_nodes().add(childrenNode); 

The following conditions are true:

  1. radNode is a RadTreeNode that has been created
  2. It has been added to a RadTreeView already
  3. set_expanded(true) has already been called on it

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 28 Aug 2009, 06:57 AM
Hi Justin,

I tried the scenario and found it is working fine in my end. Here is the code that I tried.

ASPX:
 
<telerik:RadTreeView ID="RadTreeView1" runat="server"
    <Nodes> 
        <telerik:RadTreeNode runat="server" Text="New Node" Expanded="true">                        
        </telerik:RadTreeNode> 
    </Nodes> 
</telerik:RadTreeView> 

JavaScript:
 
<script type="text/javascript"
function addNodes() 
   var tree= $find("<%= RadTreeView1.ClientID %>");      
   tree.trackChanges(); 
   var radNode = tree.findNodeByText("New Node"); 
   var childrenNode = new Telerik.Web.UI.RadTreeNode(); 
   childrenNode.set_text("New Node1"); 
   radNode.get_nodes().add(childrenNode); 
   tree.commitChanges(); 
</script> 
Hope this example help you to rectify the issue that you are facing when adding nodes from client side.

-Shinu.
0
Justin
Top achievements
Rank 1
answered on 28 Aug 2009, 02:27 PM
The problem was that I was attempting to add a node that was no longer on the tree back to the tree. Creating a new node from the old node's values worked however.
Tags
TreeView
Asked by
Justin
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Justin
Top achievements
Rank 1
Share this question
or