【问题标题】:Yesod: How to build parameterized routesYesod:如何构建参数化路由
【发布时间】:2011-09-18 01:46:42
【问题描述】:

我尝试在运行时在 hamlet 模板内将参数传递给路由。

  buildFeedRow :: Item [Attribute Text] -> GWidget a a ()
  buildFeedRow item = do
    let f = unpackItem item
        u :: Text = url f
    [whamlet|
    <tr>
      <td>
        <a href="#{url f}">#{url f}
      <td>#{nextCrawlTime f}
      <td>#{crawlDelay f}
      <td>
         <a href="@{DeleteFeedR u}">Delete
      <td>Edit |]

由于类型错误而失败。

Couldn't match type `Route a' with `ConsoleRoute'
Expected type: ConsoleRoute -> [(Text, Text)] -> Text
Actual type: Route a -> [(Text, Text)] -> Text
Expected type: GHandler
                 a a (ConsoleRoute -> [(Text, Text)] -> Text)
  Actual type: GGHandler
                 a
                 a
                 (Data.Enumerator.Iteratee Data.ByteString.Internal.ByteString IO)
                 (Route a -> [(Text, Text)] -> Text)
In the first argument of `lift', namely `getUrlRenderParams'
In the first argument of `(>>=)', namely `lift getUrlRenderParams'

我的问题是如何将参数传递给 hamlet 模板中的路由。

【问题讨论】:

  • 我看不出这段代码有什么问题,我猜这里还有别的东西在起作用。也许尝试添加一些类型签名,或者在您的 sn-p 中包含更多周围的代码。

标签: haskell yesod hamlet


【解决方案1】:

我认为您的小部件的类型签名可能过于通用。由于您使用的是路线,它现在取决于您的基础类型,因此它应该具有类型

buildFeedRow :: Item [Attribute Text] -> GWidget YourFoundation YourFoundation ()

【讨论】:

    猜你喜欢
    • 2017-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多