Building a website (I’m new to web and Scala and Playframework but have a lot of programming experience) and trying to print out parts of my domain model. I have a domain model with Category -> Goal -> Task. Task knows about the Goal and Goal knows about the Category. Now i’d like to print it out like this
Category1
Goal1
Activity1
Goal2
Activity2
Activity3
I use Scala and has done this:
@tasks.groupBy(_.goal).map { case (goal, tasks) =>
<ul>
<li>@goal.name</li>
<ul>
@tasks.map { task =>
<li>@task.name</li>
}
</ul>
</ul>
}
So now it is sorted like this:
Goal1
Activity1
Goal2
Activity2
Activity3
But i would also like to sort I by Category, like the first example i showed. Is there a nice way to do this in Scala or should I change my domain model?
Regards, Lina
You can accomplish this by adding another
groupBy:Or, equivalently:
This just takes the map you get from your current approach and groups it by the category of its goal keys, giving you a
Map[Category, Map[Goal, Seq[Task]]], which you could use like this:Note that I’ve also adjusted your nesting a bit.