-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathListView.js
46 lines (39 loc) · 885 Bytes
/
ListView.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
var ListView = Backbone.View.extend({
initialize: function(){
var self = this;
$('form').on("submit", function(e){
e.preventDefault();
self.addNote();
});
this.collection.on("add", this.render, this);
},
// events: {
// 'submit': 'formSubmit'
// },
tagName: 'ul',
// events: {
// 'submit': function(e){
// e.preventDefault();
// this.addNote();
// }
// },
formSubmit: function(){
e.preventDefault();
alert('hello');
},
addNote: function(){
var text = $('input').val();
var newNote = new Note(text);
this.collection.add(newNote);
$('input').val("");
// this.render();
},
render: function(){
//this.$el.children.detach();
return this.$el.html(
this.collection.map(function(note){
return new NoteView({model: note}).render();
})
);
}
});