Copied to clipboard

Flag this post as spam?

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


  • Arun 141 posts 404 karma points
    Nov 03, 2021 @ 08:48
    Arun
    0

    Check value exists in any of the Ancestor nodes

    Hi
    I have a list of items from different parent nodes.
    I just need to avoid those nodes whose any of the ancestors have a particular checkbox checked. (for eg: hide checkbox)
    Not just the parent, any of the ancestor nodes should not be hidden.
    Is there any LINQ code?
    -Thanks

  • Frank Laumann 39 posts 303 karma points
    Nov 03, 2021 @ 09:07
    Frank Laumann
    0

    Hi Arun

    I'm not sure I understand excactly what you are trying to do. But sounds like you want to use a LINQ expression to get an array of certain ancestors that meets certain requirements. If a checkbox alias is "hideNode" you could do something a like:

    Model.Ancestors().Where(a => !a.Value<bool>("hideNode"))
    

    Or use AncestorsOrSelf if you want to include the current node.

    Then get the items from only the allowed nodes. The other way around as you describe it is also possible but not as simple and I would need more information to come up with a suggestion for that.

    Best regards Frank

  • Arun 141 posts 404 karma points
    Nov 03, 2021 @ 10:09
    Arun
    0

    Thanks Frank,
    I want to select various nodes from a list based on the value from ancestor nodes. Suppose any of the ancestors of an item has a particular field checked as hidden, then that item will be filtered out.
    -Arun

  • Frank Laumann 39 posts 303 karma points
    Nov 03, 2021 @ 10:14
    Frank Laumann
    100

    So something like

    List<IPublishedContent> list;
    list = list.Where(item => item.Ancestors().All(a => !a.Value<bool>("alias")));
    

    This filters out all items in the list that has an acestor with the propert "alias" checked.

  • Arun 141 posts 404 karma points
    Nov 03, 2021 @ 10:57
    Arun
    0

    Thanks, Frank,
    This is what exactly I wanted.
    Thanks a lot
    -Arun

Please Sign in or register to post replies

Write your reply to:

Draft