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/site/content/tutorial/06-bindings/08-each-block-bindings/app-a/App.svelte

40 lines
597 B

<script>
let todos = [
{ done: false, text: 'finish Svelte tutorial' },
{ done: false, text: 'build an app' },
{ done: false, text: 'world domination' }
];
function add() {
todos = todos.concat({ done: false, text: '' });
}
function clear() {
todos = todos.filter(t => !t.done);
}
</script>
<h1>Todos</h1>
{#each todos as todo}
<div>
<input
type=checkbox
checked={todo.done}
>
<input
placeholder="What needs to be done?"
value={todo.text}
>
</div>
{/each}
<button on:click={add}>
Add new
</button>
<button on:click={clear}>
Clear completed
</button>