Copied to clipboard

Flag this post as spam?

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


  • Dan Evans 631 posts 1018 karma points
    May 15, 2015 @ 11:19
    Dan Evans
    0

    Descendants rather than ChildrenAsList

    Is there equivalent code that will get the descendants of a node as a list like this:

    node.ChildrenAsList.ToList();

    e.g.

    node.DescendantsAsList.ToList();

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    May 15, 2015 @ 11:29
    Dennis Aaen
    0

    Hi Dan,

    You could use .Descendants() the method returning either all pages (children, grandchildren and so on) below a given page in the content tree.

    So something like this

    node.Descendants()
    

    You can see the different collections methods here https://our.umbraco.org/projects/developer-tools/umbraco-v6-mvc-razor-cheatsheets I know it says for Umbraco 6, but you can also use it for Umbraco 7. It´s just some pdf files with an overview of the different methods.

    Hope this helps,

    /Dennis

  • Dan Evans 631 posts 1018 karma points
    May 15, 2015 @ 11:36
    Dan Evans
    0

    Thanks but it throws this error:

    error CS1061: 'umbraco.NodeFactory.Node' does not contain a definition for 'Descendants' and no extension method 'Descendants' accepting a first argument of type 'umbraco.NodeFactory.Node' could be found (are you missing a using directive or an assembly reference?)

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    May 15, 2015 @ 12:02
    Dennis Aaen
    0

    Hi Dan,

    What if you do something like this:

    var node = new DynamicNode(xxx);
    var children = node.Descendants("yourDocTypeAlias");
    

    I found it on stackoverflow here: http://stackoverflow.com/questions/20629673/where-on-specific-node-children-returns-does-not-contain-a-definition-for-where

    Hope this helps,

    /Dennis

  • Dan Evans 631 posts 1018 karma points
    May 15, 2015 @ 12:10
    Dan Evans
    0

    Thanks but no joy I'm afraid. Maybe I should explain what I'm trying to achieve. I need to output JSON for all descendants of a node. I'm using this script which I'm trying to adapt as at hte moment it only returns child nodes

    https://our.umbraco.org/projects/website-utilities/node-2-json

Please Sign in or register to post replies

Write your reply to:

Draft