【问题标题】:How can I customize grails select tag如何自定义 grails 选择标签
【发布时间】:2017-10-19 05:25:57
【问题描述】:

我要自定义 grails 选择标签

我试过这段代码

<g:select name="totalHour" from="${1..20}" value="${holdingVacationInstance}"/>

此代码选择选项如下所示

1, 2, 3, ... , 20

那我怎么能这样

0.5, 1.0, 1.5, ... , 20.0

【问题讨论】:

    标签: select grails gsp


    【解决方案1】:

    你可以这样使用

    <g:select name="totalHour" from="${(0.5..20).step(1)}" value="${holdingVacationInstance}"/>
    

    然后它会给出像[0.5, 1.5, 2.5, 3.5, ...] 这样的输出,因为我担心你不能使用非整数步长。看这里http://grails.asia/groovy-range-examples

    【讨论】:

      【解决方案2】:

      使用 'from' 属性,您必须将选择选项作为列表或 Groovy Range 提供。

      IMO 后者是一种更可靠的方法:

      Groovy range with a 0.5 step size

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-10-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多