触发事件时获取 ID 属性(订阅)

Getting ID attribute when event is fired (subscriptions)

我订阅了当用户在某些 div 上写东西时计算(Calculate String 消息)的内容(contenteditable)。

subscriptions : CvModel -> Sub Msg
subscriptions _ = 
    onKeyUp (Decode.succeed Calculate) -- I need add the id element in message.

但是,我如何才能获得用户正在写入的 div 的 id 属性?

您传递给 onKeyUp 的解码器正在解码事件对象,因此您可以提取 target 元素的 id 属性(很像 targetValue).

onKeyUp (Decode.at ["target", "id"] Decode.string |> Decode.map Calculate)

https://ellie-app.com/9MVn2Zsxptva1

上有一个示例应用程序