3
模式,我有一個這樣的輸入:榆樹如何更新基於輸入型號
input [ type' "number", onInput NewValue ] [ text <| toString model.value ]
如何更新模型?我有這樣的事情:
NewValue nb ->
({ model | value = nb }, Cmd.none)
我不知道,如果在輸入類型號的值是一個Int
或String
。 我也試試這個:
NewValue nb ->
let
nb = Result.withDefault 0 (String.toInt nb)
in
({ model | value = nb }, Cmd.none)
與第二個版本,我得到這個錯誤:
The return type of function `withDefault` is being used in unexpected ways.
44| nb = Result.withDefault 0 (String.toInt nb)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The function results in this type of value:
Int
Which is fine, but the surrounding context wants it to be:
String
你的第二次嘗試看起來不錯。什麼不工作? – farmio
我添加了錯誤 – BoumTAC