Copied to clipboard

Flag this post as spam?

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


  • Alex 3 posts 23 karma points
    Oct 06, 2009 @ 01:53
    Alex
    0

    How to get a parent node in Render function?

    Hi,

    I'm trying to create a custom tree of business objects like:

    Banks
     - Bank1
     - Bank2
         - Products
             - Mortgages
             - Credit Cards

    Stuff like that. Click on nodes on a different level will open a different page (using JS, like in example). If it was the only type of objects, there wouldn't be any problem. In Render function I get this id of a node (which was set with GetTreeDialogUrl function. But in case I have a number of different objects, just ID is not enough, because I can have a bank with ID=1 and one of its products with the same ID. If I could get an information about the parent node, I could identify a category of the object and eventually load a correct page with this object properties.

    May be I'm missing something, but I can't figure out how I could get any more info other than ID of a node after a click on expand button in the tree. Does anyone have any ideas?

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Oct 06, 2009 @ 09:22
    Aaron Powell
    0

    All Umbraco nodes store the parent ID as well as the a Path (which is a comma-separated string of the hierarchy). You could use either of these to look back up the structure.

    LINQ to Umbraco (coming in 4.1) has an AncestorOrDefault method which allows you to look back up the parent hierarchy as well, but unless you're game to take on a alpha release it may not be useful :P

  • Alex 3 posts 23 karma points
    Oct 09, 2009 @ 02:03
    Alex
    0

    I suppose you mean I can get the node by its ID? Is it really possible given the IDs that I assign to nodes are not unique (e.g. we can have a parent node (Bank) with ID=1 and one ot its child nodes (products) can have the same ID=1. I tried to find any sample, but all I see is just a two-level hierachy. Here's a simple code of mine, may be the whole approach is wrong?

     

     

     

    public override void Render(ref XmlTreetree) {

    if (this.id == this.StartNodeID) {

     

     

    var banks = XmlTreeNode.Create(this);

    banks.NodeID =

    "1";

    banks.Text =

    "Banks";

     

    banks.Action = "javascript:openBanks()";

    banks.Source =

    this.GetTreeDialogUrl(1);

    tree.Add(banks);

    }

     

    else{

     

    if (this.id == 1) {

     

    List<Bank> myBankList = Bank.GetAllBanks(); // getting business objects from database

     

    foreach (Bank myBank in myBankList) {

     

    var banks = XmlTreeNode.Create(this);

    banks.NodeID = myBank.ID.ToString();

    banks.Text = myBank.Name;

     

    banks.Action =

    "javascript:openBankProperties(" + myBank.ID.ToString() + ")";

    banks.Source =

    this.GetTreeDialogUrl(????????

    }

    So this is where I stuck. Say I have some business object under this specific Bank object and this object also have the ID=1. In that case I see no way to tell the type of object or anything that could lead to that by just ID that umbraco gives me in Render function. Sorry, may be it's too obvious, I'm just started with umbraco, any ideas are welcome. 

     

  • Sa 118 posts 152 karma points
    Oct 29, 2009 @ 09:58
    Sa
    0

    hello alex .,

    have you found out the issue?

    i am having same issue as well

Please Sign in or register to post replies

Write your reply to:

Draft