在框架中播放框架Scala元组

时间:2013-07-10 12:04:27

标签: scala playframework-2.0

我正在尝试比较两个Seq字符串,我使用Apache LDAP API和Play! Scala框架。 几天后,我没有想法。 这是开始:

  

@(比较:Seq [Compare],compare1:Seq [Compare],compareForm:Form [(String,String)])(隐式请求:Request [Any])

     

@import helper ._

     

@main(“管理工具”,request.uri){

我有两个互动 - 如何比较它们?

@for(compare <- compares) {
    <td>@for(group <- compare.memberOf) {
        <li style="list-style-type: none;">@group.replaceAll(",(.*)","").replaceAll("(.*)=","")</li>
    }</td>
}
@for(compare1 <- compares1) {
    <td>@for(group1 <- compare1.memberOf) {
        <li style="list-style-type: none;">@group1.replaceAll(",(.*)","").replaceAll("(.*)=","")</li>
    }</td>
}   

1 个答案:

答案 0 :(得分:0)

我知道这可能是一个迟到的答案,但我当时设法解决了这个问题。 代码可能有点脏,但我希望它能派上用场。

模型部分:

def intersection(c1:Seq[String], c2:Seq[String]): Seq[String] = {
    (Set(c1: _*) & Set(c2: _*)).toSeq
}

控制器部分:

compareForm.bindFromRequest.fold(
hasErrors = {errors => BadRequest(views.html.compares.index(compareForm, username, User.find(username)))},
success = { ldapName => 
  val leftUser = Compare.findAll(ldapName._1)
  val rightUser = Compare.findAll(ldapName._2)
  val intersection = Compare.intersection(leftUser.memberOf,rightUser.memberOf) 
  val rightLacking: Seq[String] = (leftUser.memberOf.toSet -- intersection.toSet).toList.map(_.toString).sorted      
  val leftLacking: Seq[String] = (rightUser.memberOf.toSet -- intersection.toSet).toList.map(_.toString).sorted
  val bothOk: Seq[String] = (intersection.toSet).toList.sorted
  Ok(views.html.compares.list(leftUser, rightUser, rightLacking, leftLacking, bothOk, compareForm, username, User.find(username)))
}  )

问候!