Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tobias 16 posts 61 karma points
    Jun 25, 2009 @ 10:39
    Tobias
    0

    Creating a section tree

    I am currently in the making of a XmlTree for a new section in Umbraco 4. There was no problem adding the new section and also no problem adding the root node and first level nodes to the tree.

    However when I try to build the tree with different child nodes I just cant get it to work. Either the child nodes are not added as I expect them to or the child nodes are added infinitely, where they add themselves every time I open a node.

    I have tried to read the available documentation but I cant figure out to build a custom tree and actually making it work with many child nodes. I suspect I might have the wrong way of thinking since Im thinking about how a normal Xml document is created in C#,  where nodes are added to each other and so on.


    Basically my question is: how do I add a custom child node to a node and in what method? Also what checks do I need in the method if any? I have tried in the render method but this method seems to be called more than once for a tree.

    Is this in any way the correct approach? (in the Render-method)

     

     

     

    newNode.Source = this.GetTreeServiceUrl(newNode2.NodeID);

    newNode.Source = this.GetTreeServiceUrl(newNode2.NodeID);

     

     

     

     

    So any help would be appreciated!

  • Tobias 16 posts 61 karma points
    Jun 25, 2009 @ 10:42
    Tobias
    0

    Code got messed up and dont find the edit button so here goes again:

               XmlTreeNode newNode = XmlTreeNode.Create(this);
                newNode.Text = "Test1";
                newNode.NodeID = "-2";
                newNode.Action = "javascript:gotoURL('http://test.com');";
                newNode.Icon = FolderIcon;
                newNode.OpenIcon = FolderIconOpen;

                XmlTreeNode newNode2 = XmlTreeNode.Create(this);
                newNode2.Text = "Test2";
                newNode2.NodeID = "-3";
                newNode2.Action = "javascript:gotoURL('http://test.com');";
                newNode2.Icon = FolderIcon;
                newNode2.OpenIcon = FolderIconOpen;

                newNode.Source = this.GetTreeServiceUrl(newNode2.NodeID);

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Jun 25, 2009 @ 13:22
    Aaron Powell
    2

    There are two ways in which you can create the child nodes when doing a custom tree, either add the children as a different tree or have logic to determine which child node type to add. The first option is really good if you want to make a lot of custom logic for the child tree or if you want to be able to reuse the tree.

    The second option is what is often the easiest to work with. When Render(ref XmlTree) is called by the TreeService AJAX call it passes in some information about the current node, such as the ID, and this is generally the best to check. So you have your Render method like this:

    public override Render(ref XmlTree tree) {
    if(this.id == -1) {
    var node = XmlTreeNode.Create(this);
    node.NodeID = "1";
    // do some other setup stuff
    tree.treeCollection.Add(node);
    } else if(this.id == 1) {
    // do some stuff to make a child node
    }

     

    Also, when you reach the end depth of the nodes make sure you set the node.HasChildren property to false.

Please Sign in or register to post replies

Write your reply to:

Draft