使用链接提升传递数据

发布于 2024-11-17 19:31:23 字数 773 浏览 0 评论 0原文

通过链接传递数据的“最佳”方式是什么?

目前,我将数据保存在 SessionVAr 中并从另一端取出。但这感觉非常笨拙。还有其他方法可以做到这一点吗?

object activeHw extends SessionVar[Box[Hw]](Empty)

object AddHwScreen extends LiftScreen {
  object hw extends ScreenVar(activeHw.is.getOrElse(Hw.createRecord))
  addFields(() => hw.is)
  def finish() = {
    redirectTo("/hw")
  }
}

class HwSnippet extends StatefulSnippet with PaginatorSnippet[Hw] {
  var dispatch: DispatchIt = {
    case "showAll" => showAll _
  }

  def showAll(xhtml: NodeSeq): NodeSeq = {
    page.flatMap(hw => {
      (".hwDetail *" #> link ("hw/detail", () => activeHw.set(Full(hw)), Text("Detail")) &
       ".hwSn *" #> hw.sn).apply(xhtml)
    })
  }

  def redirectToHome = {
    redirectTo("/hw")
  }
}

What is the "best" way to pass Data with a Link?

In the moment i save the Data in a SessionVAr and get it out on the other side. But that feels very clumsy. Is there a other way to do that?

object activeHw extends SessionVar[Box[Hw]](Empty)

object AddHwScreen extends LiftScreen {
  object hw extends ScreenVar(activeHw.is.getOrElse(Hw.createRecord))
  addFields(() => hw.is)
  def finish() = {
    redirectTo("/hw")
  }
}

class HwSnippet extends StatefulSnippet with PaginatorSnippet[Hw] {
  var dispatch: DispatchIt = {
    case "showAll" => showAll _
  }

  def showAll(xhtml: NodeSeq): NodeSeq = {
    page.flatMap(hw => {
      (".hwDetail *" #> link ("hw/detail", () => activeHw.set(Full(hw)), Text("Detail")) &
       ".hwSn *" #> hw.sn).apply(xhtml)
    })
  }

  def redirectToHome = {
    redirectTo("/hw")
  }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

紫﹏色ふ单纯 2024-11-24 19:31:23

如果您有:

object MyInfo extends RequestVar("nothing")

则:

val str = (new java.util.Date).toString
S.redirectTo("/", () => MyInfo.set(str))

您通过在执行redirectTo 之前计算该值来捕获该值,然后执行将RequestVar 设置为该值的函数。 RequestVar 可以被目标页面访问。

If you have:

object MyInfo extends RequestVar("nothing")

Then:

val str = (new java.util.Date).toString
S.redirectTo("/", () => MyInfo.set(str))

You capture the value by calculating it before doing the redirectTo, then execute a function that sets a RequestVar to the value. The RequestVar can be accessed by the target page.

在风中等你 2024-11-24 19:31:23

如果它在 SessionVar 中,则无需在链接中传递它。只需在下一个片段中访问它即可。

更新:抱歉,我误读了你的问题。您已经这样做了,但宁愿将其传递到链接上(作为查询参数?)。一般来说,这不是 Lift 的做事方式:有人可以更改值等。如果您确实愿意,可以向链接添加查询参数,然后在下一个代码段中使用 S.param( “名字”)

If it's in a SessionVar then there's no need to pass it in the link. Just access it in the next Snippet.

Update: Sorry, I misread your question. You are already doing that but would rather pass it on the link (as a query parameter?). Generally that isn't the Lift way of doing things: someone could change the value, etc. If you really want to you can add a query param to the link and then access it in the next Snippet with S.param("the-name").

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文