scala - LiftWeb Loc.Template 参数

标签 scala lift

我有模板和两个片段。我可以在模板中获取 ID 以选择动态片段吗?

def remote =
  Menu.param[Point]("Test1", "remote",
  id => inTransaction(Points.lookup(id)), _.id) / "point" / * / "remote" >>
  //inTransaction(Points.lookup(id)) match
  //  case point.Kind.remote =>
  Loc.Template(() => Templates("point" :: "remote" :: Nil).openOr(Nil)) >> Hidden
  //  case point.Kind.otherremote =>
  //Loc.Template(() => Templates("point" :: "otherremote" :: Nil).openOr(Nil)) >> Hidden

最佳答案

您应该使用ValueTemplate,它提供当前解析的值作为参数。

下面的代码未经测试,但您应该明白:

def remote = Menu.param[Point]("Test1", "remote",
  id => inTransaction(Points.lookup(id)), _.id) / "point" / * / "remote" >>
  Loc.ValueTemplate(point => point match
    case Full(p) if p.Kind.remote => Templates("point" :: "remote" :: Nil).openOr(Nil))
    case Full(p) if p.Kind.otherremote => Templates("point" :: "otherremote" :: Nil).openOr(Nil))
    case _ => NodeSeq.Empty
  ) >> Hidden

关于scala - LiftWeb Loc.Template 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9258275/

相关文章:

scala - 我可以使用 Jupyter Lab 通过 Scala 与 databricks Spark 集群交互吗?

Scala 选项模式匹配替代方案?

javascript - Scala Lift如何运行javascript函数并将返回值存储在变量中

lift - 从电梯中的任何映射器中按名称检索字段

scala - Haskell GHCi 打印惰性序列,但 Scala REPL 不打印

scala - 在SPARK SQL中读取分区的HIVE表

scala - 为具有 transient scala 依赖的 spring-xd 项目优化 gradle

c# - Scala (2.8)/Lift (2.2) 与 C# (4.0)/ASP.NET-MVC 3

scala - Liftweb Comet 的优点和缺点是什么?

build - 开始使用 SBT 进行提升