【发布时间】:2016-10-12 16:12:05
【问题描述】:
我有这样的输入:
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
【问题讨论】:
-
您的第二次尝试对我来说看起来不错。什么不工作?
-
我添加了错误