我在视图中遇到问题我想显示模型,所以我使用代码:
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
main =
beginnerProgram { model = model, update = update, view = view }
type alias Model = {
toto : String
}
model = { toto = "" }
type Msg = UpdateText String
update msg model =
case msg of
UpdateText text ->
{model | toto = text }
view : Model -> Html (String -> Msg)
view model =
div []
[ button [ onClick UpdateText ,value "hello" ] [ text "-" ]
, div [] [ text (toString model.toto) ]
, button [ onClick UpdateText, value "word" ] [ text "+" ]
]
我有这个错误,但我不明白我认为哪些不好:
函数
beginnerProgram
的参数导致不匹配。11 | beginnerProgram {model = model,update = update,view = view} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^函数{{ 1}}期望参数为:
beginnerProgram
但它是:
{ ..., view : { toto : String } -> Html (Msg) }
提示:
{ ..., view : Model -> Html (String -> Msg) }
字段中的问题。它看起来像一个功能需要1 更多的论点。
谢谢
答案 0 :(得分:1)
UpdateText
接受一个参数并返回Msg
值。您的视图按钮应如下所示:
button [ onClick (UpdateText "hello") ] [ text "-" ]