如何将参数从 View 传递到 Lift 中的片段?
我将使用《Exploring Lift》一书中稍微修改过的清单 4.7 来提出我的问题。
// In Boot.boot:
LiftRules.viewDispatch.append {
case List("Expenses", "recent", acctId, authToken) =>
Left(() => Full(RSSView.recent(acctId, authToken)))
// This is a dispatch via the same LiftView object. The path
// "/Site/news" will match this dispatch because of our dispatch
// method defined in RSSView. The path "/Site/stuff/news" will not
// match because the dispatch will be attempted on List("Site","stuff")
case List("Site") => Right(RSSView)
}
// Define the View object:
object RSSView extends LiftView {
def dispatch = {
case "news" => siteNews
}
def recent(acctId : String, authToken : String)() : NodeSeq = {
// User auth, account retrieval here
...
<lift:surround with="rss" at="content">
<lift:Vote.image />
</lift:surround>
}
// Display a general RSS feed for the entire site
def siteNews() : NodeSeq = { ... }
}
如何将 acctId 从最近的视图函数传递到片段 lift:Vote.image 中?谢谢。
I will use slightly modified Listing 4.7 from the book Exploring Lift to ask my question.
// In Boot.boot:
LiftRules.viewDispatch.append {
case List("Expenses", "recent", acctId, authToken) =>
Left(() => Full(RSSView.recent(acctId, authToken)))
// This is a dispatch via the same LiftView object. The path
// "/Site/news" will match this dispatch because of our dispatch
// method defined in RSSView. The path "/Site/stuff/news" will not
// match because the dispatch will be attempted on List("Site","stuff")
case List("Site") => Right(RSSView)
}
// Define the View object:
object RSSView extends LiftView {
def dispatch = {
case "news" => siteNews
}
def recent(acctId : String, authToken : String)() : NodeSeq = {
// User auth, account retrieval here
...
<lift:surround with="rss" at="content">
<lift:Vote.image />
</lift:surround>
}
// Display a general RSS feed for the entire site
def siteNews() : NodeSeq = { ... }
}
How do I pass acctId from the view function recent into the snippet lift:Vote.image? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您尝试从用户的启动中获取 acctId 和 authToekn,则这将不起作用。 Boot 仅在 Web 应用程序启动时运行,而不是为每个用户运行一次。
当用户登录时,或者当您检测到自动登录 cookie 时,您必须设置 SessionVar,然后在需要时访问 sessionVar。
If you're attempting to get the acctId and authToekn from boot for a user, this won't work. Boot only runs when the web application starts up, not once for every user.
You'll have to set SessionVar's when the user logs in, or when you detect the autologin cookie, and then access the sessionVar where you need it.