我尝试创建html节点,但遇到此错误:
Web/View/HardwareVendors/Show.hs:7:33
• Couldn't match expected type ‘Text’
with actual type ‘Data.MonoTraversable.Element mono0’
The type variable ‘mono0’ is ambiguous
• In the second argument of ‘forEach’, namely ‘renderInput’
In the first argument of ‘toHtml’, namely
‘((forEach hardwareVendor.required_fields) renderInput)’
In the expression:
toHtml ((forEach hardwareVendor.required_fields) renderInput)
|
7 | html ShowView { .. } = [hsx|
| ^...
字符串
相关源代码:
module Web.View.HardwareVendors.Show where
import Web.View.Prelude
data ShowView = ShowView { hardwareVendor :: HardwareVendor }
instance View ShowView where
html ShowView { .. } = [hsx|
{breadcrumb}
<h1>{hardwareVendor.name}</h1>
<form action="{hardwareVendor.getUrl}" method="get">
-- required_fields is a Text[] postgres column
{forEach hardwareVendor.required_fields renderInput}
<input type="submit" value="Submit">
</form>
|]
where
breadcrumb = renderBreadcrumb
[ breadcrumbLink "HardwareVendors" HardwareVendorsAction
, breadcrumbText "Show HardwareVendor"
]
renderInput :: Text -> Html
renderInput field = [hsx|
<label for="{field}">{field}</label>
<input type="text" id="{field}" name="{field}" required>
<br>
|]
型
这里有一些额外的填充字,因为堆栈溢出验证是愚蠢的。这里有一些额外的填充字,因为堆栈溢出验证是愚蠢的。
1条答案
按热度按时间g0czyy6m1#
假设这是一个正常的IHP数据库记录,则
hardwareVendor.required_fields
应该是hardwareVendor.requiredFields
,因为IHP字段始终是驼峰式大小写