【发布时间】:2016-05-11 09:25:15
【问题描述】:
我对 Grails 新的 json-views 和一对多关联有疑问。以下代码正在运行:
Foo 类:
class Foo {
String name
static hasMany = [bars:Bar]
static constraints = {
}
}
类栏:
class Bar {
String name
Foo foo
static constraints = {
}
}
foo 的 Json 视图(show.gson):
model {
Foo foo
}
json {
foo g.render(template:"foo", model:[foo:foo])
}
_foo.gson 模板:
model {
Foo foo
}
json {
name foo.name
bars foo.bars.collect { it.id }
}
但是,如果我将 foo 类更改为使用 List 代替,如下所示:
class Foo {
String name
List bars
static hasMany = [bars:Bar]
static constraints = {
}
}
我收到以下错误:
[静态类型检查] - 没有这样的属性:类的 id:java.lang.Object @ 第 13 行,第 29 列。 酒吧 foo.bars.collect { it.id }
我确信有办法解决这个问题,但我想知道是否有人经历过这种情况并知道为什么使用 List 时它不起作用。
非常感谢您的帮助。
【问题讨论】:
-
请在github.com/grails/grails-views/issues 提出请求,我们将进行查看。感谢您的反馈。
-
@jeff-scott-brown 谢谢!在此处创建请求link