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