Let's assume that we have this grid with values that can be 0 or 1:
(def grid [[1 0 1]
[1 0 0]
[1 0 1]])
Now I want to transform grid
into an html Hiccup like format using list comprehension:
(defn cell-component [is-it-1 key]
^{:key key} [:td (if (= is-it-1 1) {:class "is-it-1"})])
(defn grid-html []
([:table
[:tbody
(for [row grid]
^{:key row} [:tr
(for [cell row]
(cell-component cell how-i-can-generate-a-index?))])]]))
The table is generated correctly but I don't have any ideas to how to make a unique index
for my td
. what how-i-can-generate-a-index?
should be?