fundamental.js /js/views/TodoListView.js

Language Javascript Lines 32
MD5 Hash 82893f215137957f76e64899f99496cb
Repository git://github.com/radekstepan/fundamental.js.git View Raw File View Project SPDX
| Open JSFiddle
 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
// Todo List View
// ----------

App.Views.TodoListView = Backbone.View.extend({

	"el": "#todos",

	initialize: function(options) {
		// Bind to `todoCreated` notification so we can update the list view.
		_.bindAll(this, "addOneTodo");
		App.Mediator.bind("todoCreated", this.addOneTodo);

		// On initialization, add all existing **Todo** items.
		this.addAllTodos();
	},

	// Add a single todo item to the list by creating a view for it, and
	// appending its element to the `<ul>`.
	addOneTodo: function(todo) {
		var view = new App.Views.TodoView({model: todo});
		$("#todo-list").append(view.render().el);

		// Send a notification that we need to update the stats.
		App.Mediator.trigger("todosStatsUpdated");
	},

	// Add all items in the **Todos** collection at once.
	addAllTodos: function() {
		App.Models.Todos.each(this.addOneTodo);
	},

});
Back to Top