File tree Expand file tree Collapse file tree 3 files changed +24
-25
lines changed
content/tutorial/03-advanced-svelte/05-bindings/02-each-block-bindings Expand file tree Collapse file tree 3 files changed +24
-25
lines changed Original file line number Diff line number Diff line change @@ -7,15 +7,17 @@ You can even bind to properties inside an `each` block.
7
7
``` svelte
8
8
/// file: App.svelte
9
9
{#each todos as todo}
10
- <input
11
- type=checkbox
12
- bind:checked={todo.done}
13
- >
10
+ <div class:done={todo.done}>
11
+ <input
12
+ type="checkbox"
13
+ +++bind:+++checked={todo.done}
14
+ />
14
15
15
- <input
16
- placeholder="What needs to be done?"
17
- bind:value={todo.text}
18
- >
16
+ <input
17
+ placeholder="What needs to be done?"
18
+ +++bind:+++value={todo.text}
19
+ />
20
+ </div>
19
21
{/each}
20
22
```
21
23
Original file line number Diff line number Diff line change 1
1
<script >
2
2
let todos = [
3
- {
4
- done: false ,
5
- text: ' finish Svelte tutorial'
6
- },
3
+ { done: false , text: ' finish Svelte tutorial' },
7
4
{ done: false , text: ' build an app' },
8
5
{ done: false , text: ' world domination' }
9
6
];
19
16
todos = todos .filter ((t ) => ! t .done );
20
17
}
21
18
22
- $: remaining = todos .filter (
23
- (t ) => ! t .done
24
- ).length ;
19
+ $: remaining = todos .filter ((t ) => ! t .done ).length ;
25
20
</script >
26
21
27
22
<h1 >Todos</h1 >
28
23
29
24
{#each todos as todo }
30
25
<div class:done ={todo .done }>
31
- <input type ="checkbox" checked ={todo .done } />
26
+ <input
27
+ type =" checkbox"
28
+ checked ={todo .done }
29
+ />
32
30
33
31
<input
34
32
placeholder =" What needs to be done?"
39
37
40
38
<p >{remaining } remaining</p >
41
39
42
- <button on:click ={add }> Add new </button >
40
+ <button on:click ={add }>
41
+ Add new
42
+ </button >
43
43
44
44
<button on:click ={clear }>
45
45
Clear completed
Original file line number Diff line number Diff line change 1
1
<script >
2
2
let todos = [
3
- {
4
- done: false ,
5
- text: ' finish Svelte tutorial'
6
- },
3
+ { done: false , text: ' finish Svelte tutorial' },
7
4
{ done: false , text: ' build an app' },
8
5
{ done: false , text: ' world domination' }
9
6
];
19
16
todos = todos .filter ((t ) => ! t .done );
20
17
}
21
18
22
- $: remaining = todos .filter (
23
- (t ) => ! t .done
24
- ).length ;
19
+ $: remaining = todos .filter ((t ) => ! t .done ).length ;
25
20
</script >
26
21
27
22
<h1 >Todos</h1 >
42
37
43
38
<p >{remaining } remaining</p >
44
39
45
- <button on:click ={add }> Add new </button >
40
+ <button on:click ={add }>
41
+ Add new
42
+ </button >
46
43
47
44
<button on:click ={clear }>
48
45
Clear completed
You can’t perform that action at this time.
0 commit comments