From ccbbd5d64be8125ff0f47bf0b46577c7bfb9efc3 Mon Sep 17 00:00:00 2001 From: "Sebastian L. K. Sorensen" Date: Sat, 25 Nov 2023 22:06:21 +0100 Subject: [PATCH] example: .for() with non-object items --- example/app.js | 34 ++++++++++++++++++++++++++++++++++ example/index.html | 1 + 2 files changed, 35 insertions(+) diff --git a/example/app.js b/example/app.js index e81b8e88..5e08419a 100644 --- a/example/app.js +++ b/example/app.js @@ -69,6 +69,40 @@ const List = { } } +one({ + name: 'simple-list', + state: { + items: ['Item #1', 'Item #2', 'Item #3'] + }, + template: html` +
+ + + +
+ `, + setup ({ query, state }) { + const li = query('li') + const add = query('#add') + const reset = query('#reset') + + add.on('click', function ({ state }) { + state.items = [...state.items, `Item #${state.items.length + 1}`] + }) + + reset.on('click', function ({ state }) { + state.items.splice(1, 1) + }) + + li.for(['items'], function ({ el, item }) { + el.style.color = 'coral' + el.style.fontWeight = 'bold' + }) + } +}) + one({ name: 'my-component', components: [Test, List], diff --git a/example/index.html b/example/index.html index b4871360..48047c2e 100644 --- a/example/index.html +++ b/example/index.html @@ -34,6 +34,7 @@ +

Hejsa