0

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

应用程序.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"/>
4

1 回答 1

2

你有这个:

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使用小写字母,并且您希望将 2 个参数传递给,第二个参数是类文字。"i"getPropertyList

于 2019-07-01T14:50:18.287 回答