Skip to content

Commit f0b1efd

Browse files
committed
feat(app): implement removeItem to TodoItemView
- when destroy this mode, then remove this view
1 parent 759b8b8 commit f0b1efd

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

src/app.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,6 @@ $(function () {
1010
title: text
1111
});
1212
var item = new TodoItemView({model});
13-
//var $li = $('<li>');
14-
//var $text = $('<span>').addClass('todoText').text(text);
15-
//var $checkbox = $('<input type="checkbox">');
16-
//var $remove = $('<i>').addClass('removeBtn fa fa-times');
17-
//$remove.on('click', function () {
18-
// if (!window.confirm('消しますよ')) {
19-
// return;
20-
// }
21-
// $li.remove();
22-
//});
23-
//$checkbox.on('click', function () {
24-
// $li.toggleClass('is-complete');
25-
//});
26-
//$li.append($checkbox, $text, $remove);
2713
return item.render().el;
2814
}
2915

src/todo-item-view.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ class TodoItemView extends View {
1818
'click .removeBtn': 'removeItem'
1919
};
2020
super(options);
21+
22+
23+
this.listenTo(this.model, 'destroy', this.remove);
2124
}
2225

2326
// *Re-render the contents of the todo item.*
@@ -28,10 +31,15 @@ class TodoItemView extends View {
2831
}
2932

3033
toggleComplete() {
31-
34+
this.model.toggle();
3235
}
3336

3437
removeItem() {
38+
if (!window.confirm('消しますよ')) {
39+
return;
40+
}
41+
this.model.destroy();
42+
return this;
3543
}
3644
}
3745
export default TodoItemView;

0 commit comments

Comments
 (0)