0
我創建了一個使用Grails標籤的嵌套循環,但沒有得到我期待的輸出。我期待在另一組鏈接中嵌套的鏈接列表。我很近,但嵌套鏈接顯示爲一個大列表,而不是多個鏈接。Grails導航鏈接嵌套循環
我有兩個具有一對多關係的域。我的控制器目前是動態的。
writen 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>
謝謝,這幫助了這麼多。我被困在那裏幾個小時。 – Daniel 2015-03-31 17:49:47
我知道這是事實,但我想知道如果你能解釋爲什麼這個代碼更改工作。只是希望學習新東西。 – Daniel 2015-04-07 19:47:19
@Daniel在你的代碼中看到,你完成了第二個循環,比如'」將迭代3 ..現在清楚了嗎? –
2015-04-11 07:55:48