【问题标题】:Grails Taglib G:SELECTGrails 标记库 G:SELECT
【发布时间】:2012-06-28 21:03:01
【问题描述】:

我是 Grails 平台的新手,对 TagLib 组件产生了兴趣。 我有这个应用程序,其中我要创建一个由两个<select> 标签组成的时间选择 [24 小时格式选择]:小时和时间。到目前为止,我已经以这种方式编写了我的理论。

def timePicker = { attrs ->
   out << "<g:select name='" + attrs['name'] + ".hour' from='${00..21}' />"
   out << "<g:select name='" + attrs['name'] + ".minute' from='${00..59}' />" 
}

但是我无法在页面中显示它,但它在网页本身中显示out 的内容,这是错误的。 TagLib 如何在.gsp 上正确显示两个&lt;select&gt;?我是用传统的&lt;select&gt;&lt;option&gt; 语句编写它,还是使用g.select(attrs) 语法?

谢谢

【问题讨论】:

    标签: html grails taglib


    【解决方案1】:

    你可以使用这样的东西:

    def timePicker = { attrs ->
        def hours = 0..21
        def stringHours = hours.collect{ String.format('%02d', it) }
    
        def minutes = 0..59
        def stringMinutes = minutes.collect{ String.format('%02d', it) }
    
        out << "${select(from: stringHours, name: attrs.name + '.hour')}"
        out << "${select(from: stringMinutes, name: attrs.name + '.minute')}"
    }
    

    【讨论】:

      【解决方案2】:

      您只能在 GSP 中使用方法调用:

      def timePicker = { attrs ->
          out << "${select(from: 00..21, name: attrs.name + '.hour')}"
          out << "${select(from: 00..59, name: attrs.name + '.minute')}"
       }
      

      【讨论】:

      • 谢谢。但是有没有办法格式化单个数字 [0-9] 以使其格式化为两位数 0\d?谢谢。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-13
      • 2012-09-12
      • 1970-01-01
      • 1970-01-01
      • 2022-09-14
      • 1970-01-01
      相关资源
      最近更新 更多