榆树 - Select标签内的动态Html选项标签

时间:2015-12-05 04:26:31

标签: elm

榆树新手在这里。

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

select

我收到Elm Compiler“Type Mismatch”错误:

  

函数List VirtualDom.Node 期望第二个参数为:

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

这是从哪里来的?

#!/bin/bash
src=""
targ=${PWD}

while getopts "s:t:" opt; do
  case $opt in
    s)
      src=$OPTARG
      ;;
    t)
      targ=$OPTARG
      ;;
  esac
  shift $((OPTIND-1))
done

echo "Source: $src"
echo "Target: $targ"

1 个答案:

答案 0 :(得分:5)

List.map已经返回一个列表,但你仍然在方括号中,所以它包含在另一个列表中。用括号括起来:

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