grails - Grails 3中的下拉列表

标签 grails grails-3.3

我正在使用Grails 3.3.10开发应用程序,试图创建一个下拉列表,但我将其清空为空,将值放入application.yml文件中,以下是我的代码。

application.yml:

profile:
   accType: ['supplier', 'buyer', 'both']

域:
class Profile {
String accType
static constraints = {
accType(nullable: true, InList: Holders.config.getProperty('profile.accType'))
  }

} 

_form.gsp
<g:select required="" style="width:auto;" class="form-control input" name="accType" from="${Profile.constrainedProperties.accType.inList}" value="${profileInstance?.accType}" valueMessagePrefix="profile.accType"/>

最佳答案

你有这个:

static constraints = {
    accType(nullable: true, InList: Holders.config.getProperty('profile.accType'))
}

您可能想要这样:
static constraints = {
    accType(nullable: true, inList: Holders.config.getProperty('profile.accType', List))
}

请注意,InList应该是inList,开头是小写"i",并且您想将2个参数传递给getProperty,第二个参数是List类文字。

关于grails - Grails 3中的下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56828349/

相关文章:

grails - grails:获取多个hasmany列表

mongodb - Grails 3-MongoDB的GORM-副本集的最近读取

grails - Grails 3.3-如何替换已弃用的服务伪像?

Grails:运行插件时服务未注入(inject) Controller

chalice 3.3 : Is only the first save() persisted?

grails - 如何在 grails 3.3.9 中为禁止的 url 访问显示自定义错误页面

grails - gradle 属性文件位于 gradle 项目中的哪里?

ide - 如何使IntelliJ IDEA 8.1.x忽略.gitignore中的项目

file - Grails fileUpload限制

angularjs - 如何将服务注入(inject) Grails 3 命令?