Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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())
{
}
Hi Mark,
Not sure if you'd copied your code exactly as you had it? If so, then try capitalising .Reverse().
.Reverse()
Cheers, - Lee
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....
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:
.AncestorsOrSelf()
@foreach (var item in Model.Content.AncestorsOrSelf()) { @item.Level<br> }
yes sorry my debug mode didnt seem to be showing me the right data....
No worries... is it working for you now?
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
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())
{
}
Hi Mark,
Not sure if you'd copied your code exactly as you had it? If so, then try capitalising
.Reverse()
.Cheers,
- Lee
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....
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:Cheers,
- Lee
yes sorry my debug mode didnt seem to be showing me the right data....
No worries... is it working for you now?
is working on a reply...