【问题标题】:why we using closures in g:select optionvalue为什么我们在 g:select optionvalue 中使用闭包
【发布时间】:2012-08-31 00:31:30
【问题描述】:

我能理解什么是闭包。我可以理解下面的例子。

    def list = ['a','b','c','d']
    def newList = []

    def clos = { it.toUpperCase() }
    list.collect( newList, clos )

assert newList == ["A", "B", "C", "D"]  

我去看了 g:select 文档。我在下面看到了。

 <g:select optionKey="id" optionValue="${{it.title?.toUpperCase()}}" name="book.title" from="${bookList}" />

我不明白 ${{it.title?.toUpperCase()}}。

我理解每个对象标题转换为大写的逻辑,但为什么我们需要双“{}”..

为什么它不能使用 ${it.title?.toUpperCase()}

文档链接enter link description here

【问题讨论】:

    标签: grails groovy closures


    【解决方案1】:

    外部 ${ } 不是闭包,是 GSP Expression,只有内部 {} 是闭包。如果您只输入 ${it.title?.toUpperCase()} ,则不会将参数传递给闭包,而是传递实际的“it.title?.toUpperCase()”解析值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-18
      • 1970-01-01
      • 2011-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多