[CLOSED] Is it possible to store extra information with a tree node?

  1. #1

    [CLOSED] Is it possible to store extra information with a tree node?

    Hi,

    I'd like if possible my tree nodes to store additional information (e.g. the TYPE of item), so that I can interact with them better.

    I've added extra details about the TreeNodes in my web service:

    treeNode.CustomAttributes.Add(new ConfigItem("loctype","\"floor\""));
    And I see that going over the wire in json, but that isn't stored anywhere with the node (I don't think...). Is is possible to store this with the node so that when my context menu fires, I can pull the details back?

    Thanks
    Last edited by geoffrey.mcgill; Jan 23, 2011 at 4:24 AM. Reason: [CLOSED]
  2. #2
    Hi,

    Your code looks fine (but not sure why do you use \" - type of item should be string without \").

    To access 'loctype' attribute please use the client side TreeNode's .attributes collection.

    Example
    node.attributes.loctype
    or
    node.attributes["loctype"]
  3. #3
    I also can't reproduce using server side collection .CustomAttributes.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>TreePanel using Ajax Method - Ext.NET Examples</title>
    
        <script runat="server">
    
            [DirectMethod]
            public static string NodeLoad(string nodeID)
            {
                Ext.Net.TreeNodeCollection nodes = new Ext.Net.TreeNodeCollection();
    
                if (!string.IsNullOrEmpty(nodeID))
                {
                    Ext.Net.TreeNode treeNode = new Ext.Net.TreeNode();
                    treeNode.Text = "Node1";
                    treeNode.NodeID = "Node1";
                    treeNode.Leaf = true;
                    treeNode.CustomAttributes.Add(new ConfigItem("customAttribute", "Hi!", ParameterMode.Value));
                    nodes.Add(treeNode);
                }
    
                return nodes.ToJson();
            }
        </script>
    
        <script type="text/javascript">
            function nodeLoad(node) {
                Ext.net.DirectMethods.NodeLoad(node.id, {
                    success: function(result) {
                        var data = eval("(" + result + ")");
                        node.loadNodes(data);
                    },
    
                    failure: function(errorMsg) {
                        Ext.Msg.alert('Failure', errorMsg);
                    }
                });
            }
        </script>
    
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:TreePanel 
            ID="TreePanel1" 
            runat="server" 
            Title="Tree" 
            AutoHeight="true" 
            Border="false">
            <Root>
                <ext:AsyncTreeNode NodeID="0" Text="Root" />
            </Root>
            <Listeners>
                <BeforeLoad Fn="nodeLoad" />
            </Listeners>
        </ext:TreePanel>
        <ext:Button runat="server" Text="Test">
            <Listeners>
                <Click Handler="var node = TreePanel1.getNodeById('Node1');
                                alert(node.attributes['customAttribute']);" />
            </Listeners>
        </ext:Button>
        </form>
    </body>
    </html>
  4. #4
    Hi,

    That worked for me, although to get the attributes out I had to use node.attributes.attributes["loctype"]
    Can you demonstrate it on simple example?
  5. #5
    Quote Originally Posted by mattwoberts View Post
    Thanks,

    That worked for me, although to get the attributes out I had to use node.attributes.attributes["loctype"]..

    Ta
    Hi,

    Not sure why
    node.attributes.attributes["loctype"]
    works in your application.

    I can't reproduce this issue using the following code.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.Net Example</title>
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:TreePanel ID="TreePanel1" runat="server" AutoHeight="true">
            <Root>
                <ext:TreeNode Text="Root" Expanded="true">
                    <Nodes>
                        <ext:TreeNode NodeID="Node1" Text="Node1">
                            <CustomAttributes>
                                <ext:ConfigItem Name="customAttribute" Value="Hi!" Mode="Value" />
                            </CustomAttributes>
                        </ext:TreeNode>
                    </Nodes>
                </ext:TreeNode>
            </Root>
        </ext:TreePanel>
        <ext:Button runat="server" Text="Test">
            <Listeners>
                <Click Handler="var node = TreePanel1.getNodeById('Node1');
                                alert(node.attributes['customAttribute']);" />
            </Listeners>
        </ext:Button>
        </form>
    </body>
    </html>
    Could give a prompt how we can reproduce the issue?
  6. #6
    Thanks,

    That worked for me, although to get the attributes out I had to use node.attributes.attributes["loctype"]..

    Ta
  7. #7
    Small typo in my previous post - I needed to do attributes.children, not attributes.attributes.. HEre's an example:

    In my TreePanel, I have a Load listener:
    <Load Fn="Cablesense.treeDataLoaded" />
    In this method I want to loop through the nodes and check that extra param:

    treeDataLoaded: function (newNodes) {
        var node = newNodes.childNodes[0];
        var x = node.attributes["loctype"] // Gives me undefined
        var y = node.attributes["text"] // This works OK
        var z = node.attributes.children[0].loctype // This gets me the loctype
    Last edited by Daniil; Jan 25, 2011 at 10:13 AM. Reason: Please use [CODE] tags for any code
  8. #8
    Thank you.

    var x = node.attributes["loctype"]
    It means that this node doesn't have 'loctype' attribute.

    Its children has this attribute.

    Also you could use .childNodes property
    var z = node.childNodes[0].loctype
    instead of
    var z = node.attributes.children[0].loctype
  9. #9
    Oh of course!

    Sorry, I wasn't paying attention to that code was I?!

    Sorry about that confusion. My bad.
  10. #10
    No problem.

    Just we should sort all issues out:)

Similar Threads

  1. [CLOSED] 'RowError' Information in Store DataSource
    By UnifyEducation in forum 2.x Legacy Premium Help
    Replies: 5
    Last Post: Jun 18, 2012, 8:08 AM
  2. [CLOSED] Reload tree node
    By RCN in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: May 16, 2012, 8:39 PM
  3. [CLOSED] Tree Node Question
    By rosua in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Mar 29, 2012, 10:06 AM
  4. Replies: 0
    Last Post: Dec 19, 2011, 12:11 AM
  5. Replies: 16
    Last Post: Jul 19, 2011, 3:53 AM

Posting Permissions