2016-11-18 3 views
0

チェックボックスの "checked"値と一致させようとしているコントローラからのビュー(htmlページ)のListを操作しています。Scala @関数/ HTMLドキュメントの言語 - forループ、if文など

モデルから選択したチェックボックスの値(List A)を取得し、コントローラで取得してビューに送信します。また、モデルからチェックボックスの選択/オプション/値(リストB)を取得します。したがって、ページを表示すると、リストBを循環し、リストAを循環して一致するものがあるかどうかを確認します。一致した場合はチェックボックスを表示し、一致しない場合はチェックボックスの値を表示します。ここで

はスカラです:

@(profileForm: Form[Application.ProfileRegister], servicesList: java.util.List[Service], profile: Profile, servicesSelected: java.util.List[String]) 

@main(null) { 

... 

    <label class="title">Services Provided:<span class="required">*</span></label> 
    <div class="column column1"> 
     @for(service <- servicesList) { 
      @for(checkService <- servicesSelected) { 
       @if(checkService.equals(service.name)) { 
        <label><input type="checkbox" checked class="selectServices" name="selectServices" id="selectServices" [email protected]><span>@service.name</span></label> 
       } else { 
        <label><input type="checkbox" class="selectServices" name="selectServices" id="selectServices" [email protected]><span>@service.name</span></label> 
       }      
      } 
     } 
    </div> 

... 

} 

これは、チェックボックスの値を複製しているが、それはまたチェックした値で動作します。これは、ここに表示されます。

enter image description here

はこの正しいScalaのですか?

私の他の質問は、ビュー(html)内で使用できるScala @言語に関する文書はどこにありますか?私は検索しましたが、私が探しているものを見つけることはできません。これらのステートメント内の変数やHTMLだけを使用できますか?

私は助けてくれてありがとう!

答えて

0

クリーナー、重複を生産している余分な反復は必要ありません:テンプレート言語が「振り回す」と呼ばれ、ここで説明されて

@for(service <- servicesList) { 
    <label> 
     <input type="checkbox" @if(servicesSelected contains service.name) {checked} class="selectServices" name="selectServices" id="selectServices" [email protected]> 
     <span>@service.name</span> 
    </label>      
} 

https://www.playframework.com/documentation/2.5.x/ScalaTemplates