如何在elm中更新内部记录
我有这个型号如何在elm中更新内部记录,elm,Elm,我有这个型号 type alias Model = { exampleId : Int , groupOfExamples : GroupExamples } type alias GroupExamples = { groupId : Int , results : List String } 在我的更新函数中,如果我想更新exampleId,如下所示: { model | exampleId = updatedValue } 但是,如果我需要更新,例如,G
type alias Model =
{ exampleId : Int
, groupOfExamples : GroupExamples
}
type alias GroupExamples =
{ groupId : Int
, results : List String
}
在我的更新函数中,如果我想更新exampleId,如下所示:
{ model | exampleId = updatedValue }
但是,如果我需要更新,例如,GroupExamples中的results值,该怎么办
在该语言中进行此操作的唯一方法是分解外部记录,如下所示:
let
示例=model.groupof示例
newExamples={examples | results=[“whatever”]}
在里面
{model | groupOfExamples=newExamples}
此外,还提供了允许您:
set(groupOfExamples=>results)[“whatever”]模型
-当您有嵌套的数据结构时