ondrej
ondrej

Reputation: 997

How to render list in 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))

Upvotes: 4

Views: 2107

Answers (2)

ztsu
ztsu

Reputation: 25

For using ul see previous answer. Thanks to Chad.

I have an addition. You can't create recursive records. You should create structure like type TaxonomyTerm = TaxonomyTerm Guid String (List TaxonomyTerm).

Upvotes: 0

Chad Gilbert
Chad Gilbert

Reputation: 36375

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)

Upvotes: 8

Related Questions