我想在我的应用程序中使用g:timeZoneSelect
标记,问题是我发现生成的html选择非常繁琐。
例如。 “CST,中部标准时间(南澳大利亚/新南威尔士州)9.5:30.0”
只需“CST,中部标准时间”或“Australia / Broken_Hill”会更好
有没有一种方法可以通过我不知道的某种标签属性(无法在文档中找到任何标签)或配置来解决这些问题?
或者,最好的选择是将HTML select包裹在自定义标签lib中,然后“滚动我自己的”解决方案(Id最好不要这样做)。
谢谢
最佳答案
看一下源代码,就无法覆盖“optionValue”属性,因为它是在taglib方法本身中设置的
所以我想你得自己动手:-(
source for the original tag is here,应该是一个很好的起点。您可能需要这样的东西:
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)
}
}
然后,您可以执行以下操作:
<my:tzSelect/>
关于grails - 使用Grails g:timeZoneSelect标签?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2927162/