在Elm中解码具有8个以上字段的对象
给定一个具有8个以上字段的对象,如何对其进行解码在Elm中解码具有8个以上字段的对象,elm,Elm,给定一个具有8个以上字段的对象,如何对其进行解码 检查文档将放弃。不知道如何将其扩展到其他字段。“我的对象”包含18个字段。请尝试查看软件包,尤其是apply和(|:)函数 例如,解码一个对象,如 type alias Location = { id : Int , name : String , address : String , city : String , state : String } 您可以使用 locationDecoder :
检查文档将放弃。不知道如何将其扩展到其他字段。“我的对象”包含18个字段。请尝试查看软件包,尤其是
apply
和(|:)
函数
例如,解码一个对象,如
type alias Location =
{ id : Int
, name : String
, address : String
, city : String
, state : String
}
您可以使用
locationDecoder : Decoder Location
locationDecoder =
succeed Location
|: ("id" := int)
|: ("name" := string)
|: ("address" := string)
|: ("city" := string)
|: ("state" := string)