Copied to clipboard

Flag this post as spam?

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


  • Thomas 66 posts 88 karma points
    Dec 07, 2011 @ 14:10
    Thomas
    0

    Are child nodes included when added to a dynamic list?

    I've created a dynamicNodeList to have a list of specific nodes. But after adding nodes to the dynamicNodeList. I have difficulties in fetching the child nodes (of the document type comments) - is this because child nodes are not included when added to the list or beacuse I'm new to Razor?

    @* Get the followed nodes *@
      @{ 
      var homeNode = Model.AncestorOrSelf(1); 
      DynamicNodeList followedNodes = new DynamicNodeList();
      }
        
      @foreach (DynamicNode followedNode in homeNode.Descendants("ProcessSubprocess")) 
      {
        @* check if the currentmember is included in the followerlist then add node*@
        if (Library.NodeById(@followedNode.Id).followerList.InnerText.Contains(@currentMember)) {
         followedNodes.Add(followedNode);
        }  
      }   
      <ul>
      @foreach (DynamicNode item in followedNodes) {
        <li>
          @item.Name (@item.Comments.Count() comments)
        </li>
      }
      </ul>
  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Dec 07, 2011 @ 17:22
    Dave Woestenborghs
    0

    Hi 

     

    You can't can access documenttype properties directly on an DynamicNode object, only on a dynamic object. So you can change your code in 2 ways

     

    @foreach (dynamic item in followedNodes) {
        <li>
          @item.Name (@item.Comments.Count() comments)
        </li>
      }


    Or

    @foreach (DynamicNode item in followedNodes) {
        <li>
          @item.GetPropertyValue("Name")(@item.ChildrenAsList.Items.Count() comments)
        </li>
      }
  • Thomas 66 posts 88 karma points
    Dec 08, 2011 @ 14:38
    Thomas
    0

    Thanks

    I have no trouble getting the Name property, but only difficulties with the Children with @item.Name on the DynamicNode.

    The first way returns:

    Error loading Razor Script 
    Object reference not set to an instance of an object.

    The second way returns (also when I change "Items" to "Comments", which is the document type of the children):

    'System.Collections.Generic.List' does not contain a definition for 'Comments' and no extension method 'Comments' accepting a first argument of type 'System.Collections.Generic.List' could be found (are you missing a using directive or an assembly reference?)

    If I remove Comments (or Items) I get the Object reference not set to an instance of an object error.

    Any ideas of what I'm missing?

  • Thomas 66 posts 88 karma points
    Dec 08, 2011 @ 14:50
    Thomas
    0

    Sorry - I forgot that my member's login had timed out.

    When removing "Items" from the second way it finally worked :o)

    Moving on - I reached a new barrier - how do i list the Comments in followedNodes?

    @foreach (DynamicNode item in followedNodes.ChildrenAsList.Comments.Where("Visible").OrderBy("CreateDate desc"))

    does not seem to work

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Dec 08, 2011 @ 14:51
    Dave Woestenborghs
    0

    Try this :

    @foreach (DynamicNode item in followedNodes) {
        <li>
          @item.GetPropertyValue("Name")(@item.ChildrenAsList.Items.Count comments)
        </li>
      }
  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Dec 08, 2011 @ 14:54
    Dave Woestenborghs
    0

    Comments is not a property of a DynamicNodeList (this is what children as list returns)

    So you would need something like

     

    @foreach (DynamicNode item in followedNodes.ChildrenAsList.Items.Where(c => c.Visible && c.NodeTypeAlias == "YourNodeTypeAlias").OrderBy("CreateDate desc") {
        ...
      }
  • Thomas 66 posts 88 karma points
    Dec 08, 2011 @ 16:00
    Thomas
    0

    It doesn't seem to accept ChildrenAsList - 

    'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'ChildrenAsList' and no extension method 'ChildrenAsList' accepting a first argument of type 'umbraco.MacroEngines.DynamicNodeList' could be found (are you missing a using directive or an assembly reference?)

    Are "Items" then always used as a reference for nodes in the list?

     

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Dec 08, 2011 @ 16:05
    Dave Woestenborghs
    0

    Oops my mistake...your code should be like this

    @foreach(DynamicNode item in followedNodes)
    {
    // do your item code here
    @foreach(DynamicNode comment in item.ChildrenAsList.Items.Where(c => c.Visible && c.NodeTypeAlias == "YourNodeTypeAlias").OrderBy("CreateDate desc")) 
    {
    //do something with the comment
    }
    }

     

     

     

  • Thomas 66 posts 88 karma points
    Dec 08, 2011 @ 16:10
    Thomas
    0

    I see, but that would separate the comments in individual nodes instead of getting a full list of comments from all nodes that I can sort.

    The aim is to show the latest comments from specific followed nodes.  

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Dec 08, 2011 @ 16:54
    Dave Woestenborghs
    0

    You can merge the into a new dynamic list and sort on that ?

     

    Dave

  • Thomas 66 posts 88 karma points
    Dec 15, 2011 @ 10:25
    Thomas
    0

    Yes, good idea - which worked out well :o)

Please Sign in or register to post replies

Write your reply to:

Draft