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中,则它不起作用