Elm 如何以编程方式选择listview项?

Elm 如何以编程方式选择listview项?,elm,Elm,如何以编程方式选择listview项 我有以下列表视图: listview = select [ Html.Events.on "change" (Json.Decode.map InputContentType Html.Events.targetValue) ] [ option [ value "instructions" ] [ text "Content Type" ] , option [ value "Article" ] [ text "A

如何以编程方式选择listview项

我有以下列表视图:

listview =
    select [ Html.Events.on "change" (Json.Decode.map InputContentType Html.Events.targetValue) ]
        [ option [ value "instructions" ] [ text "Content Type" ]
        , option [ value "Article" ] [ text "Article" ]
        , option [ value "Video" ] [ text "Video" ]
        , option [ value "Answer" ] [ text "Answer" ]
        , option [ value "Podcast" ] [ text "Podcast" ]
        ]
更新:

我将发布的答案合并到下面,并将解决方案更新如下:

( isArticle, isVideo, isAnswer, isPodcast ) =
            if hasText "youtube.com" then
                ( False, True, False, False )
            else if hasText "vimeo.com" then
                ( False, True, False, False )
            else if hasText "wordpress.com" then
                ( True, False, False, False )
            else if hasText "medium.com" then
                ( True, False, False, False )
            else if hasText "stackoverflow.com" then
                ( False, False, True, False )
            else
                ( False, False, False, False )

        listview =
            select [ Html.Events.on "change" (Json.Decode.map InputContentType Html.Events.targetValue) ]
                [ option [ value "instructions" ] [ text "Content Type" ]
                , option [ value "Article", selected isArticle ] [ text "Article" ]
                , option [ value "Video", selected isVideo ] [ text "Video" ]
                , option [ value "Answer", selected isAnswer ] [ text "Answer" ]
                , option [ value "Podcast", selected isPodcast ] [ text "Podcast" ]
                ]

您可以使用
Html.Attributes.selected
函数以编程方式选择
选项之一。它接受一个
Bool
,因此无论何时
True
,它都会选择该
选项

listview =
    select [ Html.Events.on "change" (Json.Decode.map InputContentType Html.Events.targetValue) ]
        [ option [ value "instructions" ] [ text "Content Type" ]
        , option [ value "Article", selected True ] [ text "Article" ]
        , option [ value "Video" ] [ text "Video" ]
        , option [ value "Answer" ] [ text "Answer" ]
        , option [ value "Podcast" ] [ text "Podcast" ]
        ]

您可以使用
Html.Attributes.selected
函数以编程方式选择
选项之一。它接受一个
Bool
,因此无论何时
True
,它都会选择该
选项

listview =
    select [ Html.Events.on "change" (Json.Decode.map InputContentType Html.Events.targetValue) ]
        [ option [ value "instructions" ] [ text "Content Type" ]
        , option [ value "Article", selected True ] [ text "Article" ]
        , option [ value "Video" ] [ text "Video" ]
        , option [ value "Answer" ] [ text "Answer" ]
        , option [ value "Podcast" ] [ text "Podcast" ]
        ]