• 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 a Observable, the list will update whenever the Observable changes.

    Type Parameters

    • T

    Parameters

    • observable: IObservableOr<T[]>

      An array or an IObservable that contains the list of items to render.

    • builder: ((val) => CTag)

      A function that takes an item from the list and returns a CTag to render.

        • (val): CTag
        • Parameters

          • val: T

          Returns CTag

    • 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.

        • (val): any
        • Parameters

          • val: T

          Returns any

    Returns Node

    See

    https://github.com/nombrekeff/cardboard-js/wiki/Logic

    Example

    Static list

    const colors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'];
    div(
    each(colors, (color) =>
    button(color).addStyle('color', color)
    )
    );

    Example

    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