我正在为我必须使用 Scala 的视图开发一个带有 play framework v 2.1 的
应用
程序.x/Samples the Forms one
在应用程序的views文件夹中有一个名为form.scala.html的文件views.contact包
@(contactForm: Form[Contact])
@import helper._
@import helper.twitterBootstrap._
@title = {
Add a new contact <small><a href="@routes.Contacts.edit">Or edit an existing contact</a></small>
}
@phoneField(field: Field, className: String = "phone") = {
@input(field, '_label -> "Phone numbers", '_class -> className) { (id, name, value, _) =>
<input type="text" name="@name" value="@value">
<a class="removePhone btn danger">Remove</a>
}
}
@informationGroup(field: Field, className: String = "profile") = {
<div class="twipsies well @className">
<a class="removeProfile btn danger pull-right">Remove this profile</a>
@inputText(
field("label"),
'_label -> "Label"
)
@inputText(
field("email"),
'_label -> "Email"
)
<div class="phones">
@repeat(field("phones"), min = 0) { phone =>
@phoneField(phone("number"))
}
@**
* Keep an hidden block that will be used as template for Javascript copy code
**@
@phoneField(
field("phones[x].number"),
className = "phone_template"
)
<div class="clearfix">
<div class="input">
<a class="addPhone btn success">Add a phone number</a>
</div>
</div>
</div>
</div>
}
@main(title, nav = "contact") {
@if(contactForm.hasErrors) {
<div class="alert-message error">
<p><strong>Oops</strong> Please fix all errors</p>
</div>
}
@helper.form(action = routes.Contacts.submit, 'id -> "form") {
<fieldset>
<legend>General informations</legend>
@inputText(
contactForm("firstname"),
'_label -> "First name"
)
@inputText(
contactForm("lastname"),
'_label -> "Last name"
)
@inputText(
contactForm("company"),
'_label -> "Company"
)
</fieldset>
<fieldset>
<legend>Profiles</legend>
<div id="profiles">
@repeat(contactForm("informations")) { information =>
@informationGroup(information)
}
@**
* Keep an hidden block that will be used as template for Javascript copy code
**@
@informationGroup(
contactForm("informations[x]"),
className = "profile_template"
)
<div class="manage">
<a class="addProfile btn success">Add another profile</a>
</div>
</div>
</fieldset>
<div class="actions">
<input type="submit" class="btn primary" value="Insert">
<a href="@routes.Application.index" class="btn">Cancel</a>
</div>
}
该代码应该呈现这样的视图
通过按添加电话号码,一些文件被添加到表单中,它会变成这样:
让我对这段代码真正感到困惑的是这些部分以及它们是如何工作的:
@phoneField(field: Field, className: String = "phone") = {
@input(field, '_label -> "Phone numbers", '_class -> className) { (id, name, value, _) =>
<input type="text" name="@name" value="@value">
<a class="removePhone btn danger">Remove</a>
}
}
和
@repeat(field("phones"), min = 0) { phone =>
@phoneField(phone("number"))
}
@**
* Keep an hidden block that will be used as template for Javascript copy code
**@
@phoneField(
field("phones[x].number"),
className = "phone_template"
)
有人可以向我简要解释一下这些代码行的工作原理吗,请不要将博客或网站上的简短教程链接放在 Scala 我可以通过 Google 搜索自己找到
我只是在寻找关于这些代码行的简短但描述性的解释,在此先感谢!
顺便说一句,我从原始代码中删除了 javascript 代码