How to list recursion children on a GSP page?
I have a media domain
def Media {
String name
static belongsTo = [parent:Media]
static hasMany = [children:Media]
}
In the show.gsp page, I want to list all my root media (which have no parent) in a ul list, and their children and their children recursively in other ul lists. I used a tag for the first list, but I don't know how to do it recursively for children.
Do you have an idea how to do this?
Thank.
+3
source to share
1 answer
You can put the recursive part in the GSP template and then call it recursively, like this:
index.gsp
: Assuming rootMedias
passed to view
<g:each in="${rootMedias}" var="media">
<g:render template="step" model="${[media: media]}" />
</g:each>
_step.gsp
<ul>
<g:each in="${media.children}" var="child">
<li>
${child.name}
<g:render template="step" model="${[media: child]}" />
</li>
</g:each>
</ul>
+8
source to share