榆树新手。使用榆木0.18。
这是一个非常简单的SPA,有12个按钮(每个按钮带有音符值)。单击该按钮,它将显示您单击的注释。
我想通过Put
为按钮分配一个函数onClick
,然后传递一个字符串参数note
,用于更新模型。
这是我的代码:
import Html exposing (div, beginnerProgram, text, button)
import Html.Events exposing (onClick)
import List exposing (..)
main =
beginnerProgram { model = model, update = update, view = view }
-- model
model =
{ key = "C" }
keys =
["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]
-- update
type Action = Put
update msg model =
case msg note of
Put ->
{ model | key = note }
-- view
makeButton note =
button [ onClick Put note ] [text note]
view model =
div [] [
div [] [text (toString model.key)],
div [] (map makeButton keys)
]
我收到此错误:
-- NAMING ERROR -------------------------------------------------- musiccalc.elm
Cannot find variable `note`
19| case msg note of
答案 0 :(得分:0)
知道了,你输入了动作,然后在进入item
之前先评估。
stores