使用链接提升传递数据
通过链接传递数据的“最佳”方式是什么?
目前,我将数据保存在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您有:
则:
您通过在执行redirectTo 之前计算该值来捕获该值,然后执行将RequestVar 设置为该值的函数。 RequestVar 可以被目标页面访问。
If you have:
Then:
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.
如果它在 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")
.