Copied to clipboard

Flag this post as spam?

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


  • Murray Roke 503 posts 966 karma points c-trib
    Nov 16, 2011 @ 03:07
    Murray Roke
    0

    How do I use Descendants (Func< INode, bool > func)

    Does anyone have an example of how to use this method:

    @Model.Descendants(Func< INode, bool > func)
  • Gareth Evans 142 posts 334 karma points c-trib
    Nov 16, 2011 @ 04:31
    Gareth Evans
    2

    Technically speaking, that method is for internal use.. since it's not as straight forward as you might think to use.
    Be aware that Descendants is slow, though I have plans to optimise it for 4.7.2

    In my version of the code, the parameter is DynamicBackingItem which is the 4.7.1 signature (since a DynamicNode can be Media or Content now)

    Here's a sample:

    @using umbraco.MacroEngines;
    @{
    Func<DynamicBackingItem,bool> predicate = delegate(DynamicBackingItem node) { return node.NodeTypeAlias == "TextPage"; };
    Func<DynamicBackingItem,bool> predicate2 = delegate(DynamicBackingItem node) { string bodyText = node.GetPropertyValue("bodyText"); return bodyText != null && bodyText.Contains("lorem"); };

    <ul>
    @foreach(var item in @Library.NodeById(-1).Descendants(predicate))
    {
        <li>@item.Name</li>
    }
    </ul>

    <ul>
    @foreach(var item in @Library.NodeById(-1).Descendants(predicate2))
    {
        <li>@item.Name</li>
    }
    </ul>

    }

Please Sign in or register to post replies

Write your reply to:

Draft