Grails GSP 渲染问题

发布于 2024-11-08 20:13:35 字数 631 浏览 3 评论 0原文

我有一个域类,我想在运行时执行数据库调用以将对象列表填充为属性。我有一棵带有“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

预谋 2024-11-15 20:13:35

当你调用婚姻时,你调用的是一个闭包,并且这个闭包会被返回。我认为你应该将其重新设计为一种方法,类似这样:

static transients = ['marriages'] // tell hibernate that marriages is not a persistent property

List<Marriages> getMarriages(){
    return Marriage.findAll("from Marriage as m where m.mainMember.name=:name", [name:name])    
}

这样,当你在 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:

static transients = ['marriages'] // tell hibernate that marriages is not a persistent property

List<Marriages> getMarriages(){
    return Marriage.findAll("from Marriage as m where m.mainMember.name=:name", [name:name])    
}

This way, when you call ${tree?.headMember?.marriages} in your GSP, the getMarriages() method is called and list of marriages should be returned.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文