An array or an IObservable that contains the list of items to render.
A function that takes an item from the list and returns a CTag to render.
Optional
key: ((val) => any)An optional function that returns a unique key for each item in the list. This is used to optimize the rendering process.
https://github.com/nombrekeff/cardboard-js/wiki/Logic
Static list
const colors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'];
div(
each(colors, (color) =>
button(color).addStyle('color', color)
)
);
Dynamic list
const colors = state(['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet']);
const selectedColor = state('red');
div(
each(colors, (color) =>
button(color)
.addStyle('color', color)
.stylesIf(equalTo(selectedColor, color), { fontWeight: 'bold' });
)
);
Generated using TypeDoc
Render a CTag for each item in the provided list.
each
can work with a goold old array, or with a IObservable. If you provide aObservable
, the list will update whenever theObservable
changes.