Я программирую Team Creator, в котором пользователь может написать имя игрока и его силу.(Таким образом, если предположить, что пользователь пишет 10 игроков, то сгенерировано 5 команд с 2 игроками в каждой. Я не знаю, как сохранить значения, которые пользователи записывают во вход (Значения должны быть сохранены, поскольку вход снова пуст, когда пользовательнажимает кнопку ввода, чтобы добавить следующего игрока.) Я уже инициализировал переменные и список, но я застрял, когда дело доходит до сохранения значений.
Мой существующий Код Вяза:
import Browser
import Html exposing (Html, Attribute, button, text, h1, div, input, text)
import Html.Attributes exposing (style)
import Html.Attributes exposing (..)
import Html.Events exposing (onInput)
-- MAIN
main =
Browser.sandbox { init = init, update = update, view = view }
-- MODEL
type alias Player =
{ player : String
, strength : Int
}
type alias Model =
{ content : String
, teams : List Player
}
init : Model
init =
{ content = ""
, teams = []
}
-- UPDATE
type Msg
= Change String
update : Msg -> Model -> Model
update msg model =
case msg of
Change newContent ->
{ model | content = newContent }
-- VIEW
view : Model -> Html Msg
view model =
div []
[ h1 [style "font-family" "impact"] [ text "Team Creator" ]
, div[] [ input [ placeholder "? Team 1", style "width" "300px", style "height" "30px", style "font-size" "25px", style "color" "#488aff"] [] ]
, input [ placeholder "?? Strength", style "width" "300px", style "height" "30px", style "font-size" "25px", style "color" "#32db64"] []
, div [] [ button [ style "background-color" "#66cc81", style "color" "white", style "margin-top" "20px", style "width" "300px", style "border-radius" "25px", style "height" "60px", style "font-size" "30px", style "margin-right" "70px"] [ text "+ADD" ] ]
]