私は、Scala を使用する必要があるビュー用に Play フレームワーク v 2.1 を使用してアプリケーションを開発しています。
ここで見つけることができる Play フレームワークのサンプル コードの 1 つを読み込もうとしていました
http://www.playframework.com/documentation/2.0 .x/Samples the Forms one
アプリのビュー フォルダーには、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"
)
誰かがこれらのコード行がどのように機能するかについて簡単な説明を提供してくれませんか。ブログや Web サイトの短いチュートリアルへのリンクを Scala に貼り付けないでください。Google 検索で自分で見つけることができます。
これらのコード行についての短い説明的な説明を探しています。よろしくお願いします!!
ところで、元のコードからJavaScriptコードを削除しました