【发布时间】:2017-07-22 17:36:11
【问题描述】:
如何更新列表中的项目?
我尝试了以下方法:
setFeaturedLink links link =
let
dictionary =
Dict.fromList links
result =
Dict.filter (\k v -> v.title == link.title) dictionary |> Dict.toList |> List.head
index =
case result of
Just kv ->
let
( i, _ ) =
kv
in
i
Nothing ->
-1
in
if not <| index == -1 then
Dict.update index (Just { link | isFeatured = isFeatured }) dictionary |> Dict.values
else
[]
函数
update的第二个参数导致不匹配。59| Dict.update 索引(只需 { 链接 | isFeatured = isFeatured }) 字典 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 功能
update期待 第二个参数是:Maybe { contentType : ContentType , profile : Profile , title : Title , topics : List Topic , url : Url , isFeatured : Bool } -> Maybe { contentType : ContentType , isFeatured : Bool , profile : Profile , title : Title , topics : List Topic , url : Url }但它是:
Maybe { contentType : ContentType , isFeatured : Bool , profile : Profile , title : Title , topics : List Topic , url : Url }提示:看起来一个函数还需要 1 个参数。
是否有一个简单的示例说明如何更新列表中的任意项目?
【问题讨论】:
标签: elm