File tree 4 files changed +16
-7
lines changed
4 files changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -5,5 +5,6 @@ export class TodoItem extends Component {
5
5
static props = {
6
6
todo : Object ,
7
7
onToggleState : Function ,
8
+ onRemoveTodo : Function ,
8
9
}
9
10
}
Original file line number Diff line number Diff line change 2
2
<templates xml : space =" preserve" >
3
3
4
4
<t t-name =" awesome_owl.todoitem" >
5
- <input type =" checkbox" t-on-change =" ()=> props.onToggleState(props.todo.id)" />
6
- <t t-out =" props.todo.id+'. '+props.todo.description" />
5
+ <input type =" checkbox" t-on-change =" () => props.onToggleState(props.todo.id)" />
6
+ <div t-att-class =" {'text-muted': props.todo.isCompleted, 'text-decoration-line-through': props.todo.isCompleted}" >
7
+ <t t-out =" props.todo.id + '. ' + props.todo.description" />
8
+ </div >
9
+ <span t-on-click =" () => props.onRemoveTodo(props.todo.id)" class =" fa fa-remove" ></span >
7
10
</t >
8
11
9
12
</templates >
Original file line number Diff line number Diff line change @@ -25,7 +25,14 @@ export class TodoList extends Component {
25
25
} ;
26
26
27
27
toggleState ( todoId ) {
28
- let todo = this . state . todos . find ( todo => todo . id === todoId ) ;
28
+ const todo = this . state . todos . find ( todo => todo . id === todoId ) ;
29
29
todo . isCompleted = ! todo . isCompleted ;
30
30
}
31
+
32
+ removeTodo ( todoId ) {
33
+ const index = this . state . todos . findIndex ( todo => todo . id === todoId ) ;
34
+ if ( index >= 0 ) {
35
+ this . state . todos . splice ( index , 1 ) ;
36
+ }
37
+ }
31
38
}
Original file line number Diff line number Diff line change 4
4
<t t-name =" awesome_owl.todolist" >
5
5
<br />
6
6
<input t-ref =" input_todo" t-on-keyup =" ev => this.addTodo(ev)" type =" text" placeholder =" Enter a new task" />
7
- <t t-foreach =" state.todos" t-as =" i " t-key =" i .id" >
7
+ <t t-foreach =" state.todos" t-as =" todo " t-key =" todo .id" >
8
8
<div style =" border: 1px solid black" >
9
- <div t-att-class =" {'text-muted': i.isCompleted, 'text-decoration-line-through': i.isCompleted}" >
10
- <TodoItem todo = " i" onToggleState.bind=" toggleState" />
11
- </div >
9
+ <TodoItem todo =" todo" onToggleState.bind=" toggleState" onRemoveTodo.bind=" removeTodo" />
12
10
</div >
13
11
</t >
14
12
</t >
You can’t perform that action at this time.
0 commit comments