未应用 Twirl 模板默认参数值
Twirl template default parameter value is not applied
我有一个从以下声明开始的 Play 2.5 模板:
@(title: String)(content: Html)(menu:Html = HtmlFormat.empty)(implicit request:Request[AnyContent])
因此第二个参数被声明为具有默认值。
现在在控制器中我有这个动作生成器:
def document(title:String) = Action.async{implicit request =>
documentService.findByTitle(title).map{
case Some(d) => Ok(views.html.document(d))
case None => Ok(main("No document found")(content = Html("There is no such document")))
}
}
所以我没有将 menu
参数的值传递给模板调用,我希望它能够根据默认参数值语义进行编译和工作,但是我收到了这个编译错误:
[error] D:\Projects\feed\app\controllers\MainController.scala:28: missing arguments for method apply in class main;
[error] follow this method with `_' if you want to treat it as a partially applied function
[error] case None => Ok(main("No document found")(content = Html("There is no such document")))
[error] ^
[error] one error found
[error] (compile:compileIncremental) Compilation failed
你能解释一下这里有什么问题吗?
再加一对括号。
Ok(main("No document found")(content = Html("There is no such document")()))
没有最后一个括号 - 它只是一个等待另一个参数的函数。您可以检查您调用的函数类型。我将展示我的示例:
def foo(a: Int = 3) = 41
val one = foo //wan't compile
val two: (Int) => Int = foo
val three: Int = foo()
我有一个从以下声明开始的 Play 2.5 模板:
@(title: String)(content: Html)(menu:Html = HtmlFormat.empty)(implicit request:Request[AnyContent])
因此第二个参数被声明为具有默认值。
现在在控制器中我有这个动作生成器:
def document(title:String) = Action.async{implicit request =>
documentService.findByTitle(title).map{
case Some(d) => Ok(views.html.document(d))
case None => Ok(main("No document found")(content = Html("There is no such document")))
}
}
所以我没有将 menu
参数的值传递给模板调用,我希望它能够根据默认参数值语义进行编译和工作,但是我收到了这个编译错误:
[error] D:\Projects\feed\app\controllers\MainController.scala:28: missing arguments for method apply in class main;
[error] follow this method with `_' if you want to treat it as a partially applied function
[error] case None => Ok(main("No document found")(content = Html("There is no such document")))
[error] ^
[error] one error found
[error] (compile:compileIncremental) Compilation failed
你能解释一下这里有什么问题吗?
再加一对括号。
Ok(main("No document found")(content = Html("There is no such document")()))
没有最后一个括号 - 它只是一个等待另一个参数的函数。您可以检查您调用的函数类型。我将展示我的示例:
def foo(a: Int = 3) = 41
val one = foo //wan't compile
val two: (Int) => Int = foo
val three: Int = foo()