我正在尝试从ELM中的简单数组构建元素列表.预期的结果实际上只是一个元素列表,其中1作为第一项,2作为第二项,依此类推.
import Html exposing (..)
import Html.Attributes exposing (class, id)
import List exposing (map)
theArray = [1,2,3,4,5,6]
createListItem item =
li [] [ text (toString item)]
buildList collection =
map createListItem collection
builtList = ul [] [(buildList theArray)]
main =
builtList
Run Code Online (Sandbox Code Playgroud)
但我一直在第13行得到编译器错误.我尝试过将地图元素注释为html,但我看不出应该怎么做.
The 2nd argument to function `ul` is causing a mismatch.
*13| builtList = ul [] [(buildList theArray)]*
Function `ul` is expecting the 2nd argument to be:
List VirtualDom.Node
But it is:
List (List Html)
Run Code Online (Sandbox Code Playgroud)
buildList
已经返回了一个类型的值List Html
,所以你不需要括号(buildList theArray)
.将第13行更改为:
builtList = ul [] (buildList theArray)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
780 次 |
最近记录: |