Elm lang将列表元素插入父容器中

时间:2017-10-29 04:19:25

标签: elm

我在模型中有以下类型:

type alias NetworkList =
  { networks : (List Network) }

type alias Network =
  { name: String } 

一旦我加载它们,我想在视图函数中显示ul列表。我找到了这种解决方案来迭代列表中的每个孩子:

networkPickContent: NetworkList -> Html Msg 
networkPickContent networks =
    networks 
        |> List.map networkRow
        |> ul [ class "my_class" ]


 networkRow: Network -> Html Msg
 networkRow network =
    li [] [ text network.name ]

但是真的无法正常工作,调试器会返回错误:

The right side of (|>) is causing a type mismatch.

     networks 
        |> List.map networkRow

(|>) is expecting the right side to be a:

     NetworkList -> a

 But the right side is:

     List Network -> List (Html Msg)

在这种情况下我做错了什么?将List.map用于此类目的是否合理,还是有更好的方法来显示所有子元素?

1 个答案:

答案 0 :(得分:2)

NetworkList是以网络为核心的记录。请尝试以下

networkPickContent: NetworkList -> Html Msg 
networkPickContent networkList =
    networkList.networks
        |> List.map networkRow
        |> ul [ class "my_class" ]