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/documentation/examples/05-bindings/08-each-block-bindings/App.svelte

38 lines
741 B

<script>
let todos = [
{ done: false, text: 'finir le tutoriel Svelte' },
{ done: false, text: 'construire une app' },
{ done: false, text: 'dominer le monde' }
];
function add() {
todos = todos.concat({ done: false, text: '' });
}
function clear() {
todos = todos.filter((t) => !t.done);
}
$: remaining = todos.filter((t) => !t.done).length;
</script>
<h1>Todos</h1>
{#each todos as todo}
<div>
<input type="checkbox" bind:checked={todo.done} />
<input
placeholder="Qu'avez-vous besoin de faire ?"
bind:value={todo.text}
disabled={todo.done}
/>
</div>
{/each}
<p>Encore {remaining}</p>
<button on:click={add}> Ajouter </button>
<button on:click={clear}> Effacer les tâches complétées </button>