The document describes the Backbone.js framework and how it can be used to build single page applications. It explains the core components of Backbone - Models, Collections, Views and Routers. It provides examples of initializing a Backbone application, defining models and collections, creating views to render data, and setting up routes and navigation. It also covers events, templating, and best practices for structuring Backbone code into separate JavaScript files for models, collections, views etc.
51. collection.create(attributes, [options])
var Comments = new Comments([{...}]);
Comments.create({text: "It's no big deal!"});
var comment = new Comment({
text: "It's no big deal!",
});
comment.save();
Comments.add(comment);
63. Backbone.Events
◦ "add" (model, collection) — when a model is added to a collection.
◦ "remove" (model, collection) — when a model is removed from a collection.
◦ "reset" (collection) — when the collection's entire contents have been replaced.
◦ "change" (model, collection) — when a model's attributes have changed.
◦ "change:[attribute]" (model, collection) — when a specific attribute has been updated.
◦ "destroy" (model, collection) — when a model is destroyed.
◦ "error" (model, collection) — when a model's validation fails, or a save call fails on the server.
◦ "route:[name]" (router) — when one of a router's routes has matched.
◦ "all" — this special event fires for any triggered event, passing the event name as the first
argument.
65. Backbone.sync is the function that Backbone calls every time it
attempts to read or save a model to the server. By default, it uses
(jQuery/Zepto).ajax to make a RESTful JSON request. You can
override it in order to use a different persistence strategy, such as
WebSockets, XML transport, or Local Storage.
68. Models Collections
Interactive Data Domain-
Ordered Sets of Models
specific methods
69. Models Collections
Interactive Data Domain-
Ordered Sets of Models
specific methods
Views
Render HTML/CSS With
Javascript templating
70. Models Collections
Interactive Data Domain-
Ordered Sets of Models
specific methods
Views Router
Render HTML/CSS With Methods For Routing URL
Javascript templating Fragments
71. Models Collections
Interactive Data Domain-
Ordered Sets of Models
specific methods
Views Router
Render HTML/CSS With Methods For Routing URL
Javascript templating Fragments
72. Models Collections
Interactive Data Domain-
Ordered Sets of Models
specific methods
Views Router
Render HTML/CSS With Methods For Routing URL
Javascript templating Fragments
98. new App.Views.StreamItem();
model: Status
Status model.fetch()
this.render()
Resharers new App.Views.Resharers()...
Comments
99. new App.Views.StreamItem();
model: Status
Status model.fetch()
this.render()
Resharers new App.Views.Resharers()...
new App.Views.Comments()
this.collection = new Comments([],{
id: status.id
Comments });
this.collection.fetch()
this.collection.create()
this.collection.remove()