我试图在play 2 scala教程中给出表单模板助手的说明.我陷入了"编写自己的字段构造函数"一节.它给出了一个示例模板(不说该文件的名称应该是什么):
@(elements: helper.FieldElements)
<div class="@if(elements.hasErrors) {error}">
<label for="@elements.id">@elements.label</label>
<div class="input">
@elements.input
<span class="errors">@elements.errors.mkString(", ")</span>
<span class="help">@elements.infos.mkString(", ")</span>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
然后它显示了这段代码:
object MyHelpers {
implicit val myFields = FieldConstructor(myFieldConstructorTemplate.f)
}
Run Code Online (Sandbox Code Playgroud)
我很困惑这应该与模板有什么关系.(例如,模板文件应该被称为myFieldConstructorTemplate.scala.html吗?)我尝试了一些没有运气的变化.
我是scala和Play的新手,但我也知道play 2和它的docs是新的,所以我不确定我错过了什么非常明显的东西.
谢谢!
使用doc,我可以为我的领域设置我自己的帮助器,但是我也希望个性化游戏给出的一些字段.
主要原因是Twitter Bootstrap 2,我需要更改(在checkbox.scala.html中)
@input(field, args:_*) { (id, name, value, htmlArgs) =>
<input type="checkbox" id="@id" name="@name" value="@boxValue" @(if(value == Some(boxValue)) "checked" else "") @toHtmlArgs(htmlArgs.filterKeys(_ == 'value))>
<span>@args.toMap.get('_text)</span>
}
Run Code Online (Sandbox Code Playgroud)
至 :
<label class="checkbox">
<input type="checkbox" name="@name" id="@id" value="@boxValue" @(if(value == Some(boxValue)) "checked" else "") @toHtmlArgs(htmlArgs.filterKeys(_ == 'value)) />
@args.toMap.get('_text)
</label>
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点 ?谢谢你的帮助!