Menu.param 2 params,不编译

时间:2014-02-20 22:08:24

标签: scala lift params

我正在试图理解“Menu.param”如何与2个参数一起使用

我正在使用此代码作为示例:

https://github.com/dpp/starting_point/blob/menu_fun/src/main/scala/code/snippet/AThread.scala

但我不能让它发挥作用

object APost {

  // Create a menu for /user/santo
  val menu = Menu.param[( User, Posts )]("ParamId1", "ParamId2",
    {
      case User(p1) :: Posts(p2) :: Nil =>
        Full( (p1, p2) )
      case _ =>
        Empty
    },
    params => List(params._1.id.toString,params._2.id.toString)) / * / * >> LocGroup("UserPost")

  lazy val loc = menu.toLoc

  def render = "*" #> loc.currentValue.map(_.docId)

}

编译时发送以下错误:

[error] /menu2params/src/main/scala/code/snippet/APost.scala:23: constructor cannot be instantiated to expected type;
[error]  found   : scala.collection.immutable.::[B]
[error]  required: String
[error]     case ParamId1(p1) :: ParamId1(p2) :: Nil =>
[error]                       ^
[error] one error found
[error] (compile:compile) Compilation failed

有人可以帮助我

以下是我项目的副本:

https://github.com/hectorgool/menu2params/blob/master/src/main/scala/code/snippet/APost.scala

感谢您的关注

1 个答案:

答案 0 :(得分:1)

Menu.param用于单个参数,因此错误需要String而不是ListMenu.params允许您在列表中指定多个参数。对代码进行更改可以解决问题。