Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to render list in elm?

Tags:

list

render

elm

I have a hard time to render List of custom types within the view function. This is the model:

type alias Guid = String
type alias User = String

type alias TaxonomyCategory =
  { id : Guid
  , name: String
  , updatedAt: Date
  , updatedBy: User
  , terms: List TaxonomyTerm
  }

type TaxonomyTerm =
  TaxonomyTerm
    { id : Guid
    , name: String
    , terms: List TaxonomyTerm
    }

I tried several approaches with List.map function but I always ended up with some kind of error message.

The 2nd argument to function `ul` is causing a mismatch.

120|       ul
121|         []
122|>        [ List.map renderTaxonomyTerm tc.terms ]

Function `ul` is expecting the 2nd argument to be:

    List (VirtualDom.Node a)

But it is:

    List (List (Html a))

1 Answers

The second parameter of ul should be a list of Html elements. Your second value contains a list within a list since you surrounded it with brackets. Changing it to this should fix your problem:

ul
  []
  (List.map renderTaxonomyTerm tc.terms)
like image 94
Chad Gilbert Avatar answered Sep 16 '25 09:09

Chad Gilbert