Copied to clipboard

Flag this post as spam?

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


  • Mark Evans 86 posts 116 karma points
    Sep 18, 2014 @ 12:58
    Mark Evans
    0

    looping through nodes in reverse

    how would i be able to do a foreach loop through nodes but in reverse order?

    i need to search nodes from a lower level outwards due to content populating pages down the content tree.

    i found a reverse method but had no luck...

    var nodes = root.AncestorsOrSelf();

    foreach (var node in nodes.reverse())

    }

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Sep 18, 2014 @ 13:04
    Lee Kelleher
    1

    Hi Mark,

    Not sure if you'd copied your code exactly as you had it? If so, then try capitalising .Reverse().

    Cheers,
    - Lee

  • Mark Evans 86 posts 116 karma points
    Sep 18, 2014 @ 14:06
    Mark Evans
    0

    yes sorry a typo, but regardless of this it seems to loop thru the nodes top down, ie home, level 1, level 2 etc, same as normal loop....

    im wanting to loop from the bottom node back to the home node....

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Sep 18, 2014 @ 14:23
    Lee Kelleher
    0

    Hi Mark,

    I've just tried this using MVC Views (on Umbraco 7.1.4) and when calling .AncestorsOrSelf() itself returns the ancestors (and self) in bottom-up order:

    @foreach (var item in Model.Content.AncestorsOrSelf())
    {
        @item.Level<br>
    }
    

    Cheers,
    - Lee

  • Mark Evans 86 posts 116 karma points
    Sep 18, 2014 @ 15:26
    Mark Evans
    0

    yes sorry my debug mode didnt seem to be showing me the right data....

     

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Sep 18, 2014 @ 15:28
    Lee Kelleher
    0

    No worries... is it working for you now?

Please Sign in or register to post replies

Write your reply to:

Draft