Copied to clipboard

Flag this post as spam?

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


  • Harshit 64 posts 226 karma points
    Dec 18, 2015 @ 06:33
    Harshit
    0

    How to get the parentId of the current node in custom tree using angularjs

    Hi ,

    i have a tree structure like

    Tree1

    1. Item
    2. Item 2

    Tree2

    1.Item 1

    2.Item 2

    i am trying to get the parentId of Item2 of Tree1 using angular js. can we do it?is there any property using we can do it?

    Thanks,

  • Ian 178 posts 750 karma points
    Dec 18, 2015 @ 13:16
    Ian
    0

    Hi there, what you want should be possible, the exact implementation will depend on where in the tree you are when you want to get the parentId. The key is that I don't think you can use editorState, instead you have to inject appState and treeService into your angular controller

    This will get the top most node of the current tree:

    var rootNode = appState.getTreeState("currentRootNode");
    

    This will get the current selected node in the custom tree

    var selectedNode = appState.getTreeState("selectedNode");
    

    If the current selected node has a parent the parentId property will have the appropriate value.

    If you want to do more the treeService has various methods to get children & descendants taking section name and node (retrieved using methods above) as arguments.

    See the tree service in the umbraco source here for details https://github.com/umbraco/Umbraco-CMS/blob/d50e49ad37fd5ca7bad2fd6e8fc994f3408ae70c/src/Umbraco.Web.UI.Client/src/common/services/tree.service.js

  • Harshit 64 posts 226 karma points
    Dec 21, 2015 @ 05:41
    Harshit
    0

    Thanks a lot Ian :)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies