You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte/test/runtime/samples/event-handler-each-context-.../main.svelte

15 lines
254 B

<script>
export let switches = [
{ on: false },
{ on: true },
{ on: false }
];
</script>
{#each switches as s}
<button on:click="{() => s.on = !s.on}">
{s.on ? 'on' : 'off'}
</button>
{/each}
<p>on: {switches.filter(s => !!s.on).length}</p>