我应该为scala函数参数使用函数。该函数如下所示:
def apply(field: Field, options: Seq[(String, String)], args: (Symbol, Any)*)(implicit handler: FieldConstructor, lang: Lang): Html
args
param采用如下数组:
'_label -> "mylabel", '_showConstraints -> false, 'class -> "form-control"
在播放框架中,它看起来像这样:
@helper.select(myForm("fieldName"), options = options(MyObject.options), '_label -> "mylabel", '_showConstraints -> false, 'class -> "form-control")
如何正确编写将项添加到数组的方法?像这样:
@helper.select(callForm("callee"), options = options(LineDimension.options), args('_label -> "mylabel", '_showConstraints -> false, 'class -> "form-control"))
功能:
@args(args: (Symbol, Any)*) = @{
if (!filterEnabled) {
args.add('disabled -> "disabled")
}
args
}
来自播放控制台的错误消息是:
... type mismatch;
[error] found : Seq[(Symbol, Any)]
[error] required: (Symbol, Any)
[error] @helper.select(callForm("callee"), options = options(LineDimension.options), args('_label -> Messages.get("call.callee.choose"), '_showConstraints -> false, 'class -> "form-control"))
答案 0 :(得分:5)
使用args(...): _*
@helper.select(callForm("callee"), options = options(LineDimension.options), args('_label -> Messages.get("call.callee.choose"), '_showConstraints -> false, 'class -> "form-control"): _*)
修改强>:
@args(args: (Symbol, Any)*) = @{
if (!filterEnabled) {
args :+ ('disabled -> "disabled")
} else args
}
然后像我上面提到的那样使用。