小编Gra*_*dog的帖子

如何在 Elm 中获取多选的选定选项?

我已经了解了获取单个选择的选定索引所需的内容,但我有兴趣从多选中获取所有选定的选项。我一直无法弄清楚如何做到这一点。

我尝试了以下操作,但我怀疑 Json 解码器失败。但我不能 100% 确定这一点,因为解码发生在虚拟 dom 代码中,并且那里的任何错误都会被丢弃。

type Msg
= SetMultipleInts (List Int)

-- I'm not seeing the SetMultipleInts message when I click on the multiselect
view model =
    div []
        [ select (onSelect SetMultipleInts) (List.map myOption [1..4]) ]

myOption : Int -> Html Msg
myOption id =
    option [ value (toString id) ] [ text <| "Option " ++ (toString id) ]

-- I'm not seeing anything happen in the onchange
onMultiSelect : (List Int -> …
Run Code Online (Sandbox Code Playgroud)

html-select elm

5
推荐指数
1
解决办法
826
查看次数

标签 统计

elm ×1

html-select ×1