如何将 Int 转换为 Html

How Can I Transform An Int Into Html

我正在编写一个小程序来处理和显示吉他和弦

但我卡住了:我不知道如何将一个 Int 值转换成Html。


我的小渲染函数看起来像:

renderGuitarString : GuitarString -> Html Msg
renderGuitarString guitarString =
    div [ class "string" ] --here I don't know what to do

和:

view : Model -> Html Msg
view model =
    div [] (List.map renderGuitarString model.guitarStrings)

只是为了完整的图片,我的 types 和我的 model:

type alias GuitarString =
{   number : Int
,   frets : List Fret
}

和:

type alias Fret =
    {   number : Int
    ,   tone : ( String, Int )
    }

和:

type alias Model =
    {   guitarStrings : List GuitarString
    }

我想将 Fret 数值转换为实数 Html。

感谢帮助!

更新:这在 Elm 0.19 中不起作用,请改用 String.fromInt

您使用 Html.text 来显示字符串,但问题是整数不是字符串,因此您必须使用 toString。例如:

renderGuitarStringNum : Int -> Html Msg
renderGuitarStringNum num =
    text (toString num)

您也可以将其呈现为

renderGuitarStringNum = toString >> text

renderGuitarStringNum = text << toString

对我来说,toString 没有用,可能已经过时了。但是 String.fromInt 做到了。