2012-09-06 36 views
3

我能理解什麼是閉包。我可以理解下面的例子。爲什麼我們在g中使用閉包:select optionvalue

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

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

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

我去看看g:select documentation。我在下面看到。

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

我不理解$ {{it.title?.toUpperCase()}}。

我理解的邏輯每個對象標題轉換爲大寫,但我們爲什麼需要雙「{}」 ..

爲什麼沒有使用$ {it.title工作?.toUpperCase() }

文檔鏈接enter link description here

回答

5

的outher $ {}不是關閉,是GSP Expression,僅內{}是一個封閉。如果您只放置$ {it.title?.toUpperCase()},則不會傳遞參數閉包,而會傳遞實際的「it.title?.toUpperCase()」解析值。

相關問題