1

我尝试将 html 呈现为 radiofieldList 的标签产生了以下错误。

Handler/Manager.hs:91:32:
No instance for (RenderMessage Scheduler (Handler RepHtml))
  arising from a use of `radioFieldList'
Possible fix:
  add an instance declaration for
  (RenderMessage Scheduler (Handler RepHtml))
In the first argument of `mreq', namely `(radioFieldList bPairs)'
In a stmt of a 'do' block:
  (jobRes, jobView) <- mreq
                         (radioFieldList bPairs) "Scheduled Jobs" Nothing
In the expression:
  do { let bPairs = buttonPairs kjPairs
           statusPairs
             = map (pack . show &&& id) $ ([minBound .. maxBound] :: [Status            ]);
       (jobRes, jobView) <- mreq
                              (radioFieldList bPairs) "Scheduled Jobs" Nothing;
       (noteRes, noteView) <- mreq textareaField " Notes " Nothing;
       (statusRes, statusView) <- mreq
                                    (selectFieldList statusPairs) " Status " Nothing;
       .... }

所以,给定下面的代码,创建一个实例是否有意义(RenderMessage Scheduler (Handler RepHtml))

statusForm :: RForm CapturedData
statusForm kjPairs extra = do
let bPairs = buttonPairs kjPairs
    statusPairs = map (pack . show &&& id) $
                  ([minBound .. maxBound] :: [Status])
(jobRes ,jobView) <- mreq (radioFieldList bPairs) "Scheduled Jobs" Nothing
(noteRes, noteView) <- mreq textareaField " Notes " Nothing
(statusRes, statusView) <- mreq (selectFieldList statusPairs) " Status " Nothing    -- as of 0.9.4.x it is just best to explicitly type widgetFile
let widget = toWidget ($(widgetFile "status") :: Widget)
return (CapturedData <$> jobRes <*> statusRes  <*> noteRes
       , widget)

buttonPairs :: [KeyJobPair] -> [(Handler RepHtml,KeyJobPair)]
buttonPairs kjList = sort $ map buttonPairs' kjList
  where buttonPairs' :: KeyJobPair -> (Handler RepHtml,KeyJobPair)
    buttonPairs' (KeyJobPair ((Key key), JobData (Firmware product)
                                           (Version version)
                                           (StartDate sDate)
                                            status)) =
      let (Right jid) = fromPersistValue key :: Either Text Int64
      in (hamletToRepHtml [hamlet|<a href=@{RootR}(" Job Id " ++ (show jid))>|]
         ,KeyJobPair (Key key, JobData (Firmware product)
                                       (Version version)
                                       (StartDate sDate)
                                       status))

我想到,真正的答案是创建一个接受的自定义字段,(HTML,a)而不是所需的(msg,a) radioFieldList。我希望只为创建一个实例RenderMessage会起作用。

4

1 回答 1

1

你可能不需要打电话给hamletToRepHtml那里,为什么不renderHtmlText.Hamlet

我没有在这台机器上安装 yesod(所以我无法验证),但这应该为您指明正确的方向。我假设您不希望它成为一个小部件,而您只希望它被渲染。

于 2012-02-17T00:25:49.063 回答