Elm - Select 标签内的动态 Html 选项标签

Elm - Dynamic Html Option tags within a Select tag

这里是 Elm 新手。

当我用以下

替换下面 Mpower 模块中的 CustomerSelect 元素时
customers = ["Select Customer","Customer 1","Customer 2","Customer 3"]
customerSelect =
  select [ ]
    [ List.map customerItem customers
    ]

我得到一个 Elm 编译器 "Type Mismatch" 错误:

Function select is expecting the 2nd argument to be:

List VirtualDom.Node

But it is:

List (List Html)

这是从哪里来的?

module Mpower where

import Html exposing (..)
import List exposing (..)

customerItem custname =
  option [ ] [ text custname ]

customerSelect =
  select [ ]
    [
    customerItem "Select Customer",
    customerItem "Customer 1",
    customerItem "Customer 2",
    customerItem "Customer 3"
    ]

view =
  div []
    [ customerSelect
    ]

main =
  view

List.map 已经是 returns 一个列表,但是你仍然把它放在方括号中,所以它被包裹在另一个列表中。改为将其括在括号中:

customers = ["Select Customer","Customer 1","Customer 2","Customer 3"]
customerSelect =
  select [ ]
    (List.map customerItem customers)