Grails GSP 渲染问题
我有一个域类,我想在运行时执行数据库调用以将对象列表填充为属性。我有一棵带有“headMember”属性的树,该属性是一个具有以下功能的对象:
def marriages = {
def marriages = Marriage.findAll("from Marriage as m where m.mainMember.name=:name", [name:name])
return [marriages:marriages]
}
在我的 GSP 中,我使用 ${tree?.headMember?.marriages}
来访问“headMember”模型的属性,该属性从相关控制器中的以下函数传递到视图“树”:
def show = {
def tree = Tree.get(params.id)
render(view:'show', model:[tree:tree])
}
当我在浏览器中查看此属性时,我得到:
Member$_closure1@3708ab98
我期望列表的位置。
有什么想法我做错了吗?
干杯。
I've got a domain class which I want to, at run time, do a database call to populate a list of objects as a property. I have a tree with a 'headMember' property and that property is an object which has the following function:
def marriages = {
def marriages = Marriage.findAll("from Marriage as m where m.mainMember.name=:name", [name:name])
return [marriages:marriages]
}
in my GSP, I use ${tree?.headMember?.marriages}
to access the 'headMember' property of the model which is passed to the view 'tree' from the following function in the relevant controller:
def show = {
def tree = Tree.get(params.id)
render(view:'show', model:[tree:tree])
}
when I view this in my browser, i get:
Member$_closure1@3708ab98
where I'd expect a list.
Any ideas what I'm doing wrong?
Cheers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当你调用婚姻时,你调用的是一个闭包,并且这个闭包会被返回。我认为你应该将其重新设计为一种方法,类似这样:
这样,当你在 GSP 中调用
${tree?.headMember?.marriages}
时,getMarriages()调用
方法并返回婚姻列表。When you call marriages, you are calling a closure and this closure is returned. I think that you should rework it to be a method, something like that:
This way, when you call
${tree?.headMember?.marriages}
in your GSP, thegetMarriages()
method is called and list of marriages should be returned.