0
Play documentation提到了隱式可重用塊。你可以從這裏提到的單行內容擴展並在下面複製,以顯示如何在Play html模板中使用這些塊?在Play模板中蘊含有用的方法
@implicitFieldConstructor = @{ MyFieldConstructor() }
Play documentation提到了隱式可重用塊。你可以從這裏提到的單行內容擴展並在下面複製,以顯示如何在Play html模板中使用這些塊?在Play模板中蘊含有用的方法
@implicitFieldConstructor = @{ MyFieldConstructor() }
事實上,這一想法在Custom Field Constructors documentation在這裏你可以找到相關的建築形式爲例更遠一部分的展開。
在Play框架中創建表單時,可以使用表單助手來簡化可重用輸入的創建。 Play包含幾個內置的助手,每個助手都將一個字段構造函數作爲一個隱式參數。
想象一下在視圖中創建的以下表單。
@implicitFieldConstructor = @{ helper.FieldConstructor(myFieldConstructorTemplate.f) }
@helper.form(action = routes.Application.handlePost()) {
@helper.inputText(userForm("name"))
@helper.inputText(userForm("surname"))
@helper.inputText(userForm("login"))
@helper.inputText(userForm("password"))
}
的的inputTextapply方法需要FieldConstructor作爲隱式參數。正如您所看到的,隱式模板用於爲apply方法提供一個值,而不會明確地將其傳遞給每個inputText調用。由於隱式參數,視圖中的表單定義看起來更簡潔明瞭。