2
我有以下處理/模板組合:嵌套形式,結果在Haskell
處理器/ automation.hs
data AutomationRequest = AutomationRequest {
arEnabled :: Bool
, arTemplate :: Text
, arSchedules :: Textarea
}
getAutomationR :: Handler Html
getAutomationR = do
(formWidget, formEnctype) <- generateFormPost form
defaultLayout $(widgetFile "automation")
form :: Form AutomationRequest
form extra = do
(enabledRes, enabledView) <- mreq checkBoxField "" Nothing
(templateRes, templateView) <- mreq textField (withPlaceholder "..." $ bfs (""::Text)) Nothing
(schedulesRes, schedulesView) <- mreq textareaField (withPlaceholder "..." $ bfs (""::Text)) Nothing
(_, submitView) <- mbootstrapSubmit $ BootstrapSubmit ("Save"::Text) ("btn-primary"::Text) []
let requestRes = AutomationRequest <$> enabledRes <*> templateRes <*> schedulesRes
widget = $(widgetFile "automation-form")
return (requestRes, widget)
模板/ automation.hamlet
<form method=post role=form [email protected]{AutomationR} enctype=#{formEnctype}>
^{formWidget}
模板/ automation-form.hamlet
#{extra}
<div .panel .panel-default>
<div .panel-heading>^{fvInput enabledView} ...
<div .panel-body>
^{fvInput templateView}
^{fvInput schedulesView}
^{fvInput submitView}
可正常工作,但我想更多的功能:
一)我希望能夠嵌套的數據結構,如:
data AutomationRequestCollection = AutomationRequestCollection {
arcItemAbc :: AutomationRequest
, arcItemDef :: AutomationRequest
... -- 10 Items
}
data AutomationRequest = AutomationRequest {
arEnabled :: Bool
, arTemplate :: Text
, arSchedules :: Textarea
}
我不知道如何應用嵌套到let requestRes = AutomationRequest <$> enabledRes <*> templateRes <*> schedulesRes
二)回用於itemAbc,itemDef的HTML面板...:
-- loop somehow
<div .panel .panel-default>
<div .panel-heading>^{fvInput enabledView} ...
<div .panel-body>
^{fvInput templateView}
^{fvInput schedulesView}
,可以把我推到正確的方向上沒有任何想法?
很酷。謝謝。在某種程度上可以使用具有適用風格的記錄語法? '''AutomationRequestCollection {arcItemAbc = ...,arcItemDef = ...}''' – Alexander
不幸的不是。 –