简体   繁体   English

使用Grails g:timeZoneSelect标签?

[英]Working with the Grails g:timeZoneSelect tag?

I am wanting to use the g:timeZoneSelect tag within my application, problem is im finding the resulting html select to be quite overwhelming. 我想在我的应用程序中使用g:timeZoneSelect标记,问题是我发现生成的html选择相当不堪重负。

  1. Over 600 options are being displayed, IMHO this is to much to display to the user. 显示了600多个选项,恕我直言,这对用户来说太多了。 Maybe someone could point me to an example of a much more manageable list of timezones? 也许有人可以指出一个时区列表更易于管理的示例? Maybe you have seen a site that does timezone selection well? 也许您看过一个时区选择很好的网站? Im sure over 600 option is "technically" correct, but this will just look like noise to the user. 我确信超过600个选项在技术上是正确的,但是对于用户而言这就像是噪音。

  2. The display value of the timezone is to long. 时区的显示值过长。

Eg "CST, Central Standard Time (South Australia/New South Wales) 9.5:30.0" 例如:“ CST,中部标准时间(南澳大利亚/新南威尔士州)9.5:30.0”

Just "CST, Central Standard Time" or "Australia/Broken_Hill" would be better 只需“ CST,中部标准时间”或“ Australia / Broken_Hill”会更好

Is there a way to address these issues via tag attributes of some sort (cant find any in the docs) or config that I am unaware of? 有没有一种方法可以通过我不知道的某种标签属性(无法在文档中找到任何标签)或配置来解决这些问题?

Or, is my best bet to wrap an html select within a custom tag lib and "roll my own" solution (Id prefer not to). 或者,最好的选择是将HTML select包裹在自定义标签lib中,然后“滚动我自己的”解决方案(Id最好不要这样做)。

Thanks 谢谢

Having a look at the source, there's no way to override the "optionValue" attribute, as it is set in the taglib method itself 看一下源代码,就无法覆盖“ optionValue”属性,因为它是在taglib方法本身中设置的

So I guess you'd have to roll your own :-( 所以我想你得自己动手:-(

The source for the original tag is here , which should be a good starting point. 原始标签来源在此处 ,这应该是一个很好的起点。 You'd probably need something like this: 您可能需要这样的东西:

class MyNewTagLib {
    static namespace = 'my'
    def tzSelect = { attrs ->
        attrs['from'] = TimeZone.getAvailableIDs();
        attrs['value'] = (attrs['value'] ? attrs['value'].ID : TimeZone.getDefault().ID)
        def date = new Date()

        // set the option value as a closure that formats the TimeZone for display
        attrs['optionValue'] = {
            TimeZone tz = TimeZone.getTimeZone(it);
            def shortName = tz.getDisplayName(tz.inDaylightTime(date), TimeZone.SHORT);
            def longName = tz.getDisplayName(tz.inDaylightTime(date), TimeZone.LONG);

            return "${shortName}/${longName}"
        }

        // use generic select
        out << g.select(attrs)
    }
}

Then you could do: 然后,您可以执行以下操作:

<my:tzSelect/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM