diff --git a/backbone.js b/backbone.js index 2a8316f6..413a3ded 100644 --- a/backbone.js +++ b/backbone.js @@ -480,10 +480,10 @@ }); // Underscore methods that we want to implement on the Collection. - var methods = ['each', 'map', 'reduce', 'reduceRight', 'detect', 'select', - 'reject', 'all', 'any', 'include', 'invoke', 'max', 'min', 'sortBy', - 'sortedIndex', 'toArray', 'size', 'first', 'rest', 'last', 'without', - 'indexOf', 'lastIndexOf', 'isEmpty']; + var methods = ['forEach', 'each', 'map', 'reduce', 'reduceRight', 'find', 'detect', + 'filter', 'select', 'reject', 'every', 'all', 'some', 'any', 'include', + 'invoke', 'max', 'min', 'sortBy', 'sortedIndex', 'toArray', 'size', + 'first', 'rest', 'last', 'without', 'indexOf', 'lastIndexOf', 'isEmpty']; // Mix in each Underscore method as a proxy to `Collection#models`. _.each(methods, function(method) { diff --git a/index.html b/index.html index 9e4ae01c..50013f78 100644 --- a/index.html +++ b/index.html @@ -63,10 +63,15 @@ div.run:active { background-position: -51px 0; } - p, li { + p, div.container ul { margin: 20px 0; width: 550px; } + div.container ul { + list-style: circle; + font-size: 12px; + padding-left: 15px; + } a, a:visited { color: #444; text-decoration: none; @@ -82,7 +87,7 @@ font-size: 20px; } b.header { - font-size: 18px; + font-size: 16px; line-height: 30px; } span.alias { @@ -161,6 +166,7 @@ Collection
- 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();
+});
+