榆树新手在这里。

当我将以下 CustomerSelect 模块中的 Mpower 元素替换为以下元素时

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

我收到 Elm 编译器“类型不匹配”错误:



这是从哪里来的?
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 已经返回一个列表,但您仍然将它放在方括号中,因此它被包装在另一个列表中。改为将其括在括号中:

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

关于Elm - Select 标签中的动态 Html Option 标签,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34101269/

10-13 03:09