Accessing treeNode attributes in javascript

2 posts, 0 answers
  1. James
    James avatar
    5 posts
    Member since:
    Apr 2009

    Posted 13 May 2009 Link to this post

    Is there a doc anywhere that lists all the treeNode get methods? Basically I need to pull an attribute out of the selected node and I have been unable to get to it. The only things that seem to work are get_text() and get_value(). Neither of which help me.

    Thanks.

  2. Princy
    Princy avatar
    17237 posts
    Member since:
    Mar 2007

    Posted 15 May 2009 Link to this post

    Hello James,

    You can use the get_attributes() method of RadTreeNode object to get the collection of all custom attributes set to the Node. See the example shown below:

    ASPX:

     
    <telerik:RadTreeView ID="RadTreeView1"  runat="server" OnClientNodeClicked="onNodeClicked">  
       <Nodes> 
           <telerik:RadTreeNode runat="server" Text="BMW" CategoryOf="Car">  
           </telerik:RadTreeNode> 
           <telerik:RadTreeNode runat="server" Text="Red" CategoryOf="Color">  
           </telerik:RadTreeNode> 
           <telerik:RadTreeNode runat="server" Text="Mango" CategoryOf="Fruit">  
           </telerik:RadTreeNode> 
       </Nodes> 
    </telerik:RadTreeView> 

    JavaScript:
     
    <script language="javascript" type="text/javascript">  
     function onNodeClicked(sender, args)  
     {  
       var node = args.get_node();  
       alert(node.get_attributes().getAttribute("CategoryOf"));  
       //you can also set attributes, like:  
       //node.get_attributes().setAttribute("CategoryOf");  
     }  
    </script> 

    Go through the following link which lists the most important functions of the RadTreeNode object.
    RadTreeNode

    Thanks,
    Princy.

Back to Top