From f9d66a4db28c8cf3d2b4aeaf74c19156f7726254 Mon Sep 17 00:00:00 2001
From: Jeremy Ashkenas
+
Sync
@@ -517,27 +522,27 @@ one.set({
Returns the relative URL where the model's resource would be located on
the server. If your models are located somewhere else, override this method
with the correct logic. Generates URLs of the form: "/[collection]/[id]".
-
- A model with an id of 101, stored in a - Bindable.Collection with a url of "/notes", + A model with an id of 101, stored in a + Bindable.Collection with a url of "/notes", would have this URL: "/notes/101"
- +
clonemodel.clone()
Create a new instance of a model with identical attributes.
isNewmodel.isNew()
Has this model been saved to the server yet? If the model does not yet have
an id, it is considered to be new.
changemodel.change()
@@ -545,14 +550,14 @@ one.set({
aggregate rapid changes to a model, you'll want to fire the "change"
event when you're finished. Call model.change() to trigger it.
hasChangedmodel.hasChanged([attribute])
Has the model changed since the last "change" event? If an attribute
is passed, returns true if that specific attribute has changed.
book.bind("change", function() {
if (book.hasChanged("title")) {
@@ -570,14 +575,14 @@ book.bind("change", function() {
to figure out which portions of a view should be updated, or what calls
need to be made to sync the changes to the server.
-
+
previousmodel.previous(attribute)
- During a "change" event, this method can be used to get the
+ During a "change" event, this method can be used to get the
previous value of a changed attribute.
-
+
var bill = new Backbone.Model({
name: "Bill Smith"
@@ -593,12 +598,74 @@ bill.set({name : "Bill Jones"});
previousAttributesmodel.previousAttributes()
- Return a copy of the model's previous attributes. Useful for getting a
- diff between versions of a model, or for recovering from a failed validation.
+ Return a copy of the model's previous attributes. Useful for getting a
+ diff between versions of a model, or getting back to a valid state after
+ an error occurs.
+ Backbone.Collection
+
+ Collections are ordered sets of models. You can bind callbacks to be notified
+ when any model in the collection is changed, listen for "add" and
+ "remove" events, fetch the collection from the server,
+ and use a full suite of
+ Underscore.js
+ functions.
+
+
+ Underscore Methods (24)
+
+ Backbone proxies to Underscore.js to provide 24 iteration functions
+ on Backbone.Collection. They aren't all documented here, but
+ see the Underscore documentation for the full details…
+
+
+
+Books.each(function(book) {
+ book.publish();
+});
+
+var titles = Books.map(function(book) {
+ return book.get("title");
+});
+
+var publishedBooks = Books.filter(function(book) {
+ return book.get("published") === true;
+});
+
+var alphabetical = Books.sortBy(function(book) {
+ return book.author.get("name").toLowerCase();
+});
+