Grails 3.2.2从域约束中选择选项

3

是否可能使用域的约束条件填充 <select> 的选项?

static constraints = {
    variable(inList: ["value1", "value2", "value3"])
}
1个回答

5
您可以通过以下方式访问列表:
YourClass.getConstrainedProperties().yourProperty.inList

您可以在g:each循环中使用此功能来创建选择选项,或者像这样使用g:select标记:<g:select from="${YourClass.getConstrainedProperties().yourProperty.inList}" />


1
感谢@Joshua Moore将g:select标签作为替代方案添加,而不是使用g:each。这绝对是更好的方式和正确的方法! - Kloker

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接