Grails Field插件:选择一对多关系的标签

Mar*_*zzo 3 grails

我正在使用Grails 2.2.3和Fields插件1.3.我想自定义字段以使用select标签管理一对多关系.

在views/_fields/oneToMany/_input.gsp我有:

<g:select name="${property}.id" from="${type.list()}" optionKey="id" value="${value}" class="form-control one-to-many" noSelection="['null': "${label}"]" />
Run Code Online (Sandbox Code Playgroud)

但是type是一套,所以我不能使用list功能.

如何检索目标域类?

Cés*_*sar 5

只要您使用Map声明关系,例如:

static hasMany = [ books: Book ]
Run Code Online (Sandbox Code Playgroud)

您可以获取引用域的列表,该列表是beanhasMany属性的关键字,因此该属性应更改为from

from="${bean.hasMany[property].list()}"
Run Code Online (Sandbox Code Playgroud)

或者,您可以将列表传递给_input.gsp前缀变量名称的模板input-,例如

<f:field property="books" input-domainList="${bookInstaceList}" />
Run Code Online (Sandbox Code Playgroud)

在_input.gsp模板中,您可以使用变量,如下所示:

from="${domainList}"
Run Code Online (Sandbox Code Playgroud)

或混合两种方法:

from"${domainList ?: bean.hasMany[property].list()}"
Run Code Online (Sandbox Code Playgroud)