diff --git a/examples/todos/todos.js b/examples/todos/todos.js index 1c7c8486..47c7e37f 100644 --- a/examples/todos/todos.js +++ b/examples/todos/todos.js @@ -196,7 +196,6 @@ $(function(){ // Re-rendering the App just means refreshing the statistics -- the rest // of the app doesn't change. render: function() { - var done = Todos.done().length; this.$('#todo-stats').html(this.statsTemplate({ total: Todos.length, done: Todos.done().length, diff --git a/index.html b/index.html index 47ebeb5b..6112acff 100644 --- a/index.html +++ b/index.html @@ -761,13 +761,16 @@ setInterval(function() {

- In the following example, notice how because the model has never been - saved previously, our overridden version of Backbone.sync receives a "create" request. + In the following example, notice how our overridden version + of Backbone.sync receives a "create" request + the first time the model is saved and an "update" + request the second time.

 Backbone.sync = function(method, model) {
   alert(method + ": " + JSON.stringify(model));
+  model.id = 1;
 };
 
 var book = new Backbone.Model({
@@ -776,6 +779,10 @@ var book = new Backbone.Model({
 });
 
 book.save();
+
+book.save({
+  author: "Teddy"
+});
 

@@ -1145,15 +1152,25 @@ var alphabetical = Books.sortBy(function(book) {

-var ships = new Backbone.Collection;
+var Ship = Backbone.Model.extend({
+  defaults: {
+    "name":  "Black Pearl"
+  }
+});
 
-ships.bind("add", function(ship) {
+var Fleet = Backbone.Collection.extend({
+  model: Ship
+});
+
+var pirates = new Fleet();
+
+pirates.bind("add", function(ship) {
   alert("Ahoy " + ship.get("name") + "!");
 });
 
-ships.add([
+pirates.add([
   {name: "Flying Dutchman"},
-  {name: "Black Pearl"}
+  {captain: "Jack Sparrow"}
 ]);
 
@@ -1588,7 +1605,7 @@ $(function(){

Backbone.sync

- Backbone.sync is the function the Backbone calls every time it + 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,