如何将参数从 View 传递到 Lift 中的片段?

发布于 2024-12-21 18:41:47 字数 1093 浏览 4 评论 0原文

我将使用《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 技术交流群。

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

发布评论

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

评论(1

埋葬我深情 2024-12-28 18:41:47

如果您尝试从用户的启动中获取 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.

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