查看多个textareas,如何识别哪些被修改?

kas*_*tti 4 elm

textarea在Elm中创建了一个包含多个元素的简单页面.我正在努力保存数据,特别是确定哪些textarea已更新.也许一个例子说明了这一点

我从列表中查看了多个元素

type alias Model = { List Comment, ... }

type alias Comment = {id: Int, content: String, draftContent: String, ...}

type Event = Save Comment | SaveDraft String

-- view
model.comments
|> List.map(     --iterate the list of comments and render html 
div [attrubute "name" "comment"] [
  textarea [onInput SaveDraft] [text comment.content],
  button [onClick (Save comment)] [text "Post comment"]
]

-- update
case event of
  Save comment ->
    -- Replace the comment content with draft data and clear draft

  SaveDraft draftText ->
     -- Update the draft content with text from event
     -- Which Comment is it?
Run Code Online (Sandbox Code Playgroud)

根据这里的例子,我提出了将每个textarea输入作为事件发送以更新功能和保存草稿数据的想法.

现在问题是onInput只接受带String参数的类型,我无法识别哪个注释被修改.

Uri*_*ren 5

更改Event联合类型以包含注释(SaveDraft String- > SaveDraft Comment String)

type Event = Save Comment | SaveDraft Comment String

-- view
model.comments
|> List.map(     --iterate the list of comments and render html 
div [attrubute "name" "comment"] [
  textarea [onInput (SaveDraft comment.content)] [text comment.content],
  button [onClick (Save comment)] [text "Post comment"]
]
Run Code Online (Sandbox Code Playgroud)

Currying导致(SaveDraft comment.content)具有与以前相同的返回值