Grails导航链接嵌套循环 [英] Grails navigation links nested loop
问题描述
我使用Grails标签创建了一个嵌套循环,但没有获得我期待的输出。我期待在另一组链接中嵌套的链接列表。我很接近,但嵌套链接显示为一个大列表,而不是多个链接。
我有两个具有一对多关系的域。我的控制器目前是动态的。
在Grails 2.3.3中写入
以下是我的两个域
class委员会{
字符串委员名称
字符串描述
static belongsTo = [医院:医院]
静态约束= {
委员名称(可空:真)
描述(inList:[委员会,委员会))
}
}
类医院{
字符串hospitalName
$ b $静态hasMany = [委员会:委员会]
静态约束= {
hospitalName nullable:true
}
}
这里是在我的.GSP中的嵌套循环
< g:each in =$ {hospitalInstanceList}status =ivar = hospitalInstance >
< tr>
< td>
< a href =index.jsp?nav = main& hosp =<%= hospGiven%>目标= _顶部 >
< img src =/ Trustees / static / images / img / navigate.msh_board.gifborder =0>
< / a>
< / g:link>
< / td>
< / tr>
< tr>
< td>
< ul>
< p>当前ID:$ {hospitalInstance.id}< / p>
< li>
<% - < / li>
< / g:每个>
< / ul>
< / td>
< / tr>
< / g:每个>
您需要使用 $ {hospitalInstance.committees}
在内部循环中。
试试这段代码
I have created a nested loop using Grails tags but not getting the output that I am expecting. I am expecting a list of links nested within another set of links. I am close but the nested links are being displayed as one big list, not multiple links.
I have two domains with a one-to-many relationship. My controller is currently dynamic.
writen in Grails 2.3.3
Here are my two domains
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
}
}
Here is the nested loop in my .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>
You need to use ${hospitalInstance.committees}
in inner loop.
Try this code
<table border="1">
<g:each in="${hospitalInstanceList}" status="i" var="hospitalInstance">
<tr>
<td>
<g:link action="show" id="${hospitalInstance.id}">${hospitalInstance.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.committees}">
<li> <g:link action="show" id="${it.id}"> ${it.committeeName} </g:link> </li>
<br>
<li> <g:link action="show" id="${it.id}"> ${it.description}</g:link> </li>
</g:each>
</ul>
</td>
</tr>
</g:each>
</table>
这篇关于Grails导航链接嵌套循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!