html入力があります。入力イベントを聞き、モデルを更新します(ここでは単純な文字列です)。今は、モデルにInt型を使い、入力値からIntを解析したいと思います。私は別のデコーダを作り、初期モデルの値を0に変更しました。これらの変更の後、数字を入力するとモデルは変化しません。どうして?それを実装する方法は?Elmでhtml-inputをintにデコードするには?
import Html exposing (input, div, text)
import Html.Events
import StartApp.Simple
import Json.Decode
model = ""
view address model =
let
decoder =
Html.Events.targetValue
-- this decoder doesn't work
decoderInt =
Json.Decode.at ["target", "value"] Json.Decode.int
in
div [] [
input [ Html.Events.on "input" decoder (Signal.message address) ] [],
text (toString model)
]
update action model =
action
main =
StartApp.Simple.start { model = model, view = view, update = update }