你如何嵌套g:gsp中的每个标签?

Neo*_*der 5 grails gsp

假设我有以下课程

class Genre {
    static hasMany=[author:Author]
}

class Author{

    static hasMany=[books:Books]
}


class Books{
       Author author 
}
Run Code Online (Sandbox Code Playgroud)

如何使用g:每个标签在gsp中打印?

lun*_*dov 9

如果你想按作者显示所有书籍,你可能会有类似的东西

<g:each var="author" in="${Author.list()}">
    <p>Author: ${author.fullName}</p>
    <ul>
    <g:each var="book" in="${author.books}">
        <li>${book.title}</li>
    </g:each>
    </ul>
</g:each>
Run Code Online (Sandbox Code Playgroud)

干杯!

  • @Scott:你是对的!我这样做是为了清晰,因为问题是关于嵌套g:每个标签:)干杯 (2认同)