List ELM:Onlick按钮在我单击按钮时将HTML消息中的特定字符串移植到JS

List ELM:Onlick按钮在我单击按钮时将HTML消息中的特定字符串移植到JS,list,port,elm,List,Port,Elm,我有一个模型 type alias Model = { url : String , devices : List Device , input : String , isFilter : Bool , deviceSuggestion : Maybe Device } type alias Device = { status : String , license_plate : String

我有一个模型

   type alias Model =
    { 
      url : String
    , devices : List Device
    , input : String
    , isFilter : Bool
    , deviceSuggestion : Maybe Device
    }

type alias Device =
    { 
      status : String
    , license_plate : String
    , device_id : String
    }
下面是我的渲染视图,我想获得
设备的id
和JS的端口

renderPost : Device -> Html Msg
renderPost devices =
div []
    [
       [ text "Device_id : " 
        , button [ onClick PortDeviceID ] [ text (Debug.toString devices.device_id) ]
        , pre [] [ text "device_model : " , text (Debug.toString devices.device_model) ]  
        , pre [] [ text "license_plate : " , text (Debug.toString devices.license_plate) ]

     ]

renderPosts : Model -> Html Msg
renderPosts model =
([ text "Device List" ] ++ List.map (\device -> renderPost device) model.devices)
我的更新在这里。我不知道如何获取文本,因为
devices.device\u id
来自json文件

    PortDeviceID ->
         ( { model | deviceID = "" }, //port device_id --> not working)
    GotResult result ->
        case result of
            Ok devices ->
                ( { model | devices = devices }, portDevice devices ) // this give full list
我想这样做,当我单击按钮时,我可以将特定的
设备\u id
移植到JS。问题是它是
Device->Html-Msg格式的
,所以我被卡住了。有什么办法吗?任何帮助都是感激的
案件在这里解决, 在视图中,我确实喜欢下面,实例化
devices.device\u id

renderPost : Device -> Html Msg
renderPost devices =
div []
    [
       [ text "Device_id : " 
        , button [ onClick (PortDeviceID devices.device_id)] [ text (Debug.toString devices.device_id) ]
然后在更新中,同样让
portDeviceID字符串

 PortDeviceID deviceID->
         ( { model | deviceID = "" }, portDeviceID deviceID )

无论如何,感谢您的帮助Jack Leow

型号。设备
是一个
设备的列表,您不能像访问
设备一样访问它。您需要将列表映射到它上面。
([text“Device List”]++List.map(\Device->renderPost Device)model.devices)
。我以前在View.elm中这样做过。所以我需要把它重新映射到哪里?如果它位于
更新
->PortDeviceID中,则它不起作用