Functional programming 如何从导入模块的消息中提取信息?

Functional programming 如何从导入模块的消息中提取信息?,functional-programming,elm,Functional Programming,Elm,我试图以“按钮”示例()为例,从另一个模块导入它,该模块将在同一页面上显示多个按钮 我担心我仍然在考虑组件,但我还是想分享它 我创建了Main.elm,它加载了buttons示例(buttons.elm)的一个稍加修改的版本 在Main.elm中,我有一个用于生成按钮列表的button.Model列表 我现在很沮丧,因为我不知道如何从Main.elm中的Buttons.Msg获取必要的信息 要查看代码: $ git clone https://github.com/lucamug/elm-mul

我试图以“按钮”示例()为例,从另一个模块导入它,该模块将在同一页面上显示多个按钮

我担心我仍然在考虑组件,但我还是想分享它

我创建了Main.elm,它加载了buttons示例(buttons.elm)的一个稍加修改的版本

在Main.elm中,我有一个用于生成按钮列表的button.Model列表

我现在很沮丧,因为我不知道如何从Main.elm中的Buttons.Msg获取必要的信息

要查看代码:

$ git clone https://github.com/lucamug/elm-multiple-buttons.git
$ cd elm-multiple-buttons/
$ elm-package install
$ elm-reactor
打开

--解决方案

正如Chad Gilber在接受的答复中指出的那样,问题在于:

(List.indexedMap (\position buttons -> Html.map Tag (Buttons.view position buttons)) model.buttonsList)
这是正确的版本

(List.indexedMap (\position buttons -> Html.map (Tag position) (Buttons.view buttons)) model.buttonsList)

如果您对此实现感兴趣,可以在本文中找到更多详细信息。您需要更新
标记
构造函数以包含数组索引

守则的有关修订如下:

视图模型=
分区[]
(List.indexedMap(\position buttons->Html.map(标记位置)(buttons.view position buttons))model.buttonsList)
输入味精
=标记Int按钮。Msg
更新msg模型=
味精案例
标记位置按钮\u Msg->
您需要删除
update
函数中的硬编码
position=1


概述必要的更改。

您需要更新
标记
构造函数以包含数组索引

守则的有关修订如下:

视图模型=
分区[]
(List.indexedMap(\position buttons->Html.map(标记位置)(buttons.view position buttons))model.buttonsList)
输入味精
=标记Int按钮。Msg
更新msg模型=
味精案例
标记位置按钮\u Msg->
您需要删除
update
函数中的硬编码
position=1


概述必要的更改。

请粘贴问题中需要考虑的关键代码请粘贴问题中需要考虑的关键代码