【发布时间】:2025-12-19 17:05:15
【问题描述】:
我们正在尝试使用 taglib 创建自定义 g.select。我们成功地创建了它,但现在我们希望 g.select 应该有一些默认选择值。我们该怎么做?
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')}"
}
例如,以小时为单位的默认选择值可以是 12,以分钟为单位的默认值是 30。此外,我们希望从 GSP 文件中传递这些值。
即普惠制
<me:timePicker h="12" m="30" />
【问题讨论】: