Copied to clipboard

Flag this post as spam?

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


  • Rob 22 posts 133 karma points
    Sep 01, 2020 @ 12:03
    Rob
    0

    How would I get all child nodes of selected nodes in treepicker as one selection

    Hi I would like to build a query that would get all children of the parent nodes selected in a multitreepicker.

    So if I had a treepicker that selects categories, how would I return a single collection of all proucts from all of the nodes selected.

    Regards

  • Joep 96 posts 698 karma points
    Sep 01, 2020 @ 13:19
    Joep
    100

    Hi,

    I think you could do something like this:

    var allChildNodes = parentNodes.SelectMany(x => x.Children);
    

    parentNodes is the list of selected items from the MultiNodeTreePicker.

    -Joep

  • Rob 22 posts 133 karma points
    Sep 01, 2020 @ 13:41
    Rob
    0

    Perfect. Thankyou.

    First pass of code.

    @{
    var parentNodes = Model.Value<IEnumerable<IPublishedContent>>("relatedCollections");
    if(parentNodes != null ){
    var productSelection = parentNodes.SelectMany(x => x.Children);
    foreach(var productItem in productSelection){
    <p><a href="@productItem.Url">@productItem.Name</a></p>
    }}}
    

    Where relatedCollections is the MultiNode TreePicker.

    Gives the required collection.

    Cheers :)

Please Sign in or register to post replies

Write your reply to:

Draft