使用g中的枚举值:在枚举是选择对象的属性时选择 [英] using value of enum in g:select when enum is attribute of selection object

查看:161
本文介绍了使用g中的枚举值:在枚举是选择对象的属性时选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例:

batchTag是batchRange的枚举类型属性,其值为:

batchTag is an enumerated type attribute of a batchRange, with values like so:

JAN1 "January Biweekly 1",
JAN2 "January Biweekly 2",

等。

我想在选择中显示batchTag的VALUE ,IOW,选择应包含

I want to display the VALUE of the batchTag in the select, IOW, the select should contain

"January Biweekly 1"
"January Biweekly 2" ...

JAN1
JAN2
FEB1
FEB2
FEB3 ...

我已经尝试过g中的几个东西:选择这样做,但没有任何成功。我认为也许它将作为g的一部分可用:select(因为它显然是一个迭代),并尝试引用optionValue的it.batchTag.name,但是没有工作。任何建议?

I have tried several things in the g:select to do this, but without any success. I thought perhaps "it" would be available as part of the g:select (as it is clearly an iteration) and tried to reference it.batchTag.name for the optionValue, but that did not work. Any suggestions?

谢谢!

推荐答案

enum BatchRange {
    JAN1 "January Biweekly 1",
    JAN2 "January Biweekly 2",

    final String value

    BatchRange(String value) { this.value = value }

    String toString() { value } 
    String getKey() { name() }
}

请注意getKey()方法。然后你的g:选择

Note the getKey() method. And then your g:select

<g:select name="batch" from="${BatchRange.values()}" optionKey="key" />

<g:select name="batch" from="${BatchRange.values()}" keys="${BatchRange.values()*.name()}" />

这篇关于使用g中的枚举值:在枚举是选择对象的属性时选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆