【发布时间】:2015-03-31 03:38:37
【问题描述】:
我使用 Grails 标签创建了一个嵌套循环,但没有得到我期望的输出。我期待嵌套在另一组链接中的链接列表。我很接近,但嵌套链接显示为一个大列表,而不是多个链接。
我有两个具有一对多关系的域。我的控制器当前是动态的。
用 Grails 2.3.3 编写
这是我的两个域
class Committees {
String committeeName
String description
static belongsTo = [hospital:Hospital]
static constraints = {
committeeName (nullable:true)
description( inList: ["Committee","Board"])
}
}
class Hospital {
String hospitalName
static hasMany = [committees:Committees]
static constraints = {
hospitalName nullable:true
}
}
这是我的 .GSP 中的嵌套循环
<g:each in="${hospitalInstanceList}" status="i" var="hospitalInstance">
<tr>
<td>
<g:link action="show" id="${hospitalInstance.id}">${fieldValue(bean: hospitalInstance, field: "hospitalName")}</g:link>
<g:link action="show" id="${hospitalInstance.id}">
<a href="index.jsp?nav=main&hosp=<%=hospGiven %>" target="_top">
<img src="/Trustees/static/images/img/navigate.msh_board.gif" border="0">
</a>
</g:link>
</td>
</tr>
<tr>
<td>
<ul>
<g:each in="${hospitalInstance.id}" status="j" var="committeesInstance">
<p>Current id: ${hospitalInstance.id }</p>
<li>
<%-- <g:link action="show" id="${hospitalInstance}">${fieldValue(bean: hospitalInstance, field: "committees.committeeName")}</g:link>--%>
<g:link controller="Committees" action="show" id="${committeesInstanceList}">${fieldValue(bean: committeesInstance, field: "committeeName")}</g:link>
</li>
</g:each>
</ul>
</td>
</tr>
</g:each>
【问题讨论】:
标签: grails one-to-many