У меня есть список, содержащий строки (игроки) и целые числа (сильные стороны).Я достиг вывода игроков с , div [] ( if model.activatedOutput then (List.map (\{ player} -> div [] [ text player ]) model.teams) else [] )
Теперь я также хотел вывести значение силы, сохраненное в этой записи / списке.Но получите ошибку аргумента.
2-й аргумент map
- это не то, что я ожидаю:
130 |, div [] (если model.activationOutput затем (List.map ({сила} -> div [] [сила текста]) model.teams) else []) ^^^^^^^^^^^ Значение в.teams это:
List { activated : Bool, player : String, strength : Int }
Но для map
необходимо, чтобы 2-й аргумент был:
List { activated : Bool, player : String, strength : String }
Я думал, что ошибка была в том, что сила должнабыть строкой для сопоставления.Но я превратил его в строку в представлении.Так что я не совсем понимаю, откуда эта ошибка.
Вот некоторые другие части моего кода (строка, фактически вызывающая ошибку, - последняя строка в приведенном ниже коде):
-- MODEL
type alias Player =
{ player : String
, strength : Int
, activated : Bool
}
type alias Model =
{ content : String
, teams : List Player
, currentPlayer : String
, currentStrength : Int
, activatedOutput : Bool
}
-- UPDATE
...
Add ->
{ model | teams = ({player = model.currentPlayer, strength = model.currentStrength, activated = True} :: model.teams), currentPlayer = "", currentStrength = 0 }
init : Model
init =
{ content = ""
, teams = []
, currentPlayer = ""
, currentStrength = 0
, activatedOutput = False
}
-- VIEW
view : Model -> Html Msg
view model =
let
playername = "? Player " ++ String.fromInt (List.length model.teams + 1)
in
div []
[ h1 [style "font-family" "impact"] [ text "Team Creator" ]
, p [style "font-family" "sans-serif", style "font-size" "15px", style "color" "grey"] [ text "With the Team Creator you can create teams. Insert information about the name and the strength(1-5) of every player and finally how many teams you want to have created by the Team Creator" ]
, h2 [style "font-family" "impact"] [ text "Number of Teams:" ]
, input [ placeholder "Number", style "width" "300px", style "height" "30px", style "font-size" "25px", style "color" "#32db64", value (String.fromInt model.currentNumber), onInput ChangeNumber] []
, h2 [style "font-family" "impact"] [ text "Players per Team:" ]
, input [ placeholder "Playernumber", style "width" "300px", style "height" "30px", style "font-size" "25px", style "color" "#32db64", value (String.fromInt model.currentPlayernumber), onInput ChangePlayernumber] []
, h2 [style "font-family" "impact"] [ text "Name and Strength:" ]
, div[] [ input [placeholder playername, style "width" "300px", style "height" "30px", style "font-size" "25px", style "color" "#488aff", value model.currentPlayer, onInput ChangePlayer] [] ]
, input [ placeholder "?? Strength", style "width" "300px", style "height" "30px", style "font-size" "25px", style "color" "#4286F5", value (String.fromInt model.currentStrength), onInput ChangeStrength] []
, div [] [ button [ style "background-color" "#66cc81", style "color" "white", style "margin-top" "20px", style "width" "300px", style "border-radius" "25px", style "height" "40px", style "font-size" "20px", style "margin-right" "70px", onClick Add] [ text "+ADD Player" ] ]
, div [] [ button [ style "background-color" "#4286F5", style "color" "white", style "margin-top" "10px", style "width" "300px", style "border-radius" "25px", style "height" "40px", style "font-size" "20px", style "margin-right" "70px", onClick Submit] [ text "SUBMIT!" ] ]
, h2 [style "font-family" "impact", style "margin-top" "20px"] [ text "Generated Teams:" ]
, div [] ( if model.activatedOutput then (List.map (\{ player} -> div [] [ text player ]) model.teams) else [] )
, div [] ( if model.activatedOutput then (List.map (\{ strength} -> div [] [ text strength ]) model.teams) else [] )
]