私は単純なserverResponse
を定義して、elm-langのapiからの応答をシミュレートしました。elmのResult typeからHtml結果を表示するには?
Result
から情報のHTMLを表示する問題が発生しています。
これを行うにはどのような方法が最適ですか?
import String exposing (..)
import String exposing (..)
import List exposing (..)
import Result exposing (map)
import Json.Decode as Json exposing (..)
type alias Team =
{ department : String
, names: List String
}
serverResponse =
"""
[{"department":"product","names":["bob","sally","george"]},{"department":"marketing","names":["billy","diane","anita"]},{"department":"sales","names":["howard","steve","isha"]}]
"""
stringDecoder =
Json.list Json.string
infoDecoder : Json.Decoder Team
infoDecoder =
Json.map2 Team
(Json.field "department" Json.string)
(Json.field "names" stringDecoder)
teamDecoder : Json.Decoder (List Team)
teamDecoder =
Json.list infoDecoder
toList team =
p [] [
team.department
]
transformList teams =
toList teams
main =
Json.decodeString teamDecoder serverResponse
|> toString
|> text