我是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在<select>
上正确显示两个.gsp
?我是否会在传统<select>
附带<option>
语句的情况下编写它,或者我将使用g.select(attrs)
语法?
由于
答案 0 :(得分:2)
你可以使用这样的东西:
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')}"
}
答案 1 :(得分:1)
您只能在GSP中使用方法调用:
def timePicker = { attrs ->
out << "${select(from: 00..21, name: attrs.name + '.hour')}"
out << "${select(from: 00..59, name: attrs.name + '.minute')}"
}