Copied to clipboard

Flag this post as spam?

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


  • Trevor Loader 199 posts 256 karma points
    Jul 05, 2011 @ 10:15
    Trevor Loader
    0

    Sum numeric property values in children

    I would like to get the sum of 'votes' of in the children and can't quite figure it out.

    Assuming that I have a property called 'votes' as a numeric protery of the child nodes, how do I do this?

    @Model.Children.Sum(votes)

    Obviously its throwing an error that 'votes' is not defined.  Can this be done?  What's the syntax to identify the property in the Sum?

    TIA

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Jul 05, 2011 @ 10:20
    Sebastiaan Janssen
    0

    Not sure if summing has been implemented. For now you could obviously do:

    int mySum;
    @foreach(var node in Model.Children) {
    mySum = mySum + node.votes;

    Currently, you might need to do some type checking for node.votes as well, this should be a bit easier in 4.7.1.

  • Trevor Loader 199 posts 256 karma points
    Jul 05, 2011 @ 10:24
    Trevor Loader
    0

    Thanks cultiv  Looping through the nodes is what I've done but thought there might have been a "Sum" avaliable to use.

    4.7.1 must only be a week or two away so I keep an eye out for a sum in that release and update this post if it is there.

    Cheers

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Jul 05, 2011 @ 10:29
    Sebastiaan Janssen
    0

    4.7.1 beta was announced to appear during this week.

    There haven't been any commits lately containing summing. Your best bet is asking @agrath if he can build it in. Not sure if it would be too difficult at the moment though. 

     

  • Trevor Loader 199 posts 256 karma points
    Jul 12, 2011 @ 10:34
    Trevor Loader
    1

    @agrath has added the functionality to perform sum, avg, min and max today.  It'll be available in 4.7.1 when it is released.  You gotta love this community when posting on the forum has direct influence on the core!

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Jul 12, 2011 @ 10:36
    Sebastiaan Janssen
    0

    That is ace!! So you're lucky 4.7.1 got delayed then. ;)

  • Trevor Loader 199 posts 256 karma points
    Jul 12, 2011 @ 10:43
    Trevor Loader
    0

    Hell yeah.  Waiting to pull a nightly down tonight to have a play.

Please Sign in or register to post replies

Write your reply to:

Draft