Я определил простой serverResponse
, чтобы имитировать ответ от api для синтаксического анализа в elm-lang.Как отобразить результат 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