问题描述
我正在尝试在重用对象数据之前更改它。
我有一个数据类型
type alias Definition =
{ title : String,description : String,image : String
}
-- 使用来自 API 的原始数据
getDescription : Tag -> (Definition -> a) -> String -> Maybe Definition -> Html a
getDescription tag msg name def =
case def of
Just d ->
div [] [
div [] [ text d.title ],div [] [ text d.description ]
-- trying to change description with removeDescription function,div [] [ newDescription (removeDescription d) ]
]
Nothing ->
div [] [ text "name"]
newDescription : Definition -> Html a
newDescription d =
div [] [
div[] [d.title],div[] [ d.description ] -- trying to use new description
]
-- 此函数失败
removeDescription : Definition -> Definition
removeDescription d =
{ d | d.description = '' } -- This fails
我试过了
字符串.replace
但是还是不行
考虑到 Elm 确保数据不变性,是否有可能以这种方式更改数据?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)