[Pkg-javascript-commits] [backbone] 67/101: add, remove, get, getbycid, at
Jonas Smedegaard
js at moszumanska.debian.org
Sat May 3 16:58:30 UTC 2014
This is an automated email from the git hooks/post-receive script.
js pushed a commit to tag 0.1.0
in repository backbone.
commit 11c6ebb7fc346740872b27658525b07efd2c265b
Author: Jeremy Ashkenas <jashkenas at gmail.com>
Date: Tue Oct 12 13:52:59 2010 -0400
add, remove, get, getbycid, at
---
backbone.js | 10 -------
index.html | 86 +++++++++++++++++++++++++++++++++++++++++++++++++-----
test/collection.js | 5 ----
3 files changed, 79 insertions(+), 22 deletions(-)
diff --git a/backbone.js b/backbone.js
index 413a3de..2c6459f 100644
--- a/backbone.js
+++ b/backbone.js
@@ -336,16 +336,6 @@
return this.models[index];
},
- // What are the ids for every model in the set?
- getIds : function() {
- return _.keys(this._byId);
- },
-
- // What are the client ids for every model in the set?
- getCids : function() {
- return _.keys(this._byCid);
- },
-
// Pluck an attribute from each model in the collection.
pluck : function(attr) {
return _.map(this.models, function(model){ return model.get(attr); });
diff --git a/index.html b/index.html
index 50013f7..d647883 100644
--- a/index.html
+++ b/index.html
@@ -154,7 +154,6 @@
<li>– <a href="#Model-url">url</a></li>
<li>– <a href="#Model-clone">clone</a></li>
<li>– <a href="#Model-toString">toString</a></li>
- <li>– <a href="#Model-isEqual">isEqual</a></li>
<li>– <a href="#Model-isNew">isNew</a></li>
<li>– <a href="#Model-change">change</a></li>
<li>– <a href="#Model-hasChanged">hasChanged</a></li>
@@ -166,19 +165,18 @@
Collection
</a>
<ul class="toc_section">
+ <li>– <a href="#Collection-extend">extend</a></li>
<li>– <a href="#Collection-Underscore-Methods">Underscore Methods (24)</a></li>
<li>– <a href="#Collection-add">add</a></li>
<li>– <a href="#Collection-remove">remove</a></li>
<li>– <a href="#Collection-get">get</a></li>
- <li>– <a href="#Collection-getIds">getIds</a></li>
+ <li>– <a href="#Collection-getByCid">getByCid</a></li>
<li>– <a href="#Collection-at">at</a></li>
<li>– <a href="#Collection-sort">sort</a></li>
<li>– <a href="#Model-url">url</a></li>
<li>– <a href="#Collection-refresh">refresh</a></li>
<li>– <a href="#Collection-fetch">fetch</a></li>
<li>– <a href="#Collection-create">create</a></li>
- <li>– <a href="#Collection-getByCid">getByCid</a></li>
- <li>– <a href="#Collection-getCids">getCids</a></li>
<li>– <a href="#Collection-toString">toString</a></li>
<li>– <a href="#Collection-pluck">pluck</a></li>
</ul>
@@ -203,7 +201,7 @@
<div class="container">
<p>
- <img src="docs/images/backbone.png" alt="Backbone.js" />
+ <img style="width: 385px; height: 126px;" src="docs/images/backbone.png" alt="Backbone.js" />
</p>
<p>
@@ -383,7 +381,7 @@ sidebar.promptColor();
<b class="header">extend</b><code>Backbone.Model.extend(properties, [staticProperties])</code>
<br />
To create a <b>Model</b> class of your own, you extend <b>Backbone.Model</b>
- and provide instance <b>properties</b>, as well as optional properties to be attatched
+ and provide instance <b>properties</b>, as well as optional properties to be attached
directly to the constructor function.
</p>
@@ -535,6 +533,13 @@ one.set({
<br />
Create a new instance of a model with identical attributes.
</p>
+
+ <p id="Model-toString">
+ <b class="header">toString</b><code>model.toString()</code>
+ <br />
+ By default, just returns <tt>"Model [id]"</tt> — Override <b>toString</b>
+ to get convenient logging in the console for your models.
+ </p>
<p id="Model-isNew">
<b class="header">isNew</b><code>model.isNew()</code>
@@ -613,13 +618,21 @@ bill.set({name : "Bill Jones"});
<a href="http://documentcloud.github.com/underscore">Underscore.js</a>
functions.
</p>
+
+ <p id="Collection-extend">
+ <b class="header">extend</b><code>Backbone.Collection.extend(properties, [staticProperties])</code>
+ <br />
+ To create a <b>Collection</b> class of your own, extend <b>Backbone.Collection</b>,
+ providing instance <b>properties</b>, as well as optional properties to be attached
+ directly to the collection constructor function.
+ </p>
<p id="Collection-Underscore-Methods">
<b class="header">Underscore Methods (24)</b>
<br />
Backbone proxies to <b>Underscore.js</b> to provide 24 iteration functions
on <b>Backbone.Collection</b>. They aren't all documented here, but
- see the Underscore documentation for the full details…
+ you can take a look at the Underscore documentation for the full details…
</p>
<ul>
@@ -667,6 +680,65 @@ var alphabetical = Books.sortBy(function(book) {
});
</pre>
+ <p id="Collection-add">
+ <b class="header">add</b><code>collection.add(models, [options])</code>
+ <br />
+ Add a model (or an array of models) to the collection. Fires an <tt>"add"</tt>
+ event, which you can pass <tt>{silent: true}</tt> to suppress.
+ </p>
+
+<pre class="runnable">
+var ships = new Backbone.Collection();
+
+ships.bind("add", function(ship) {
+ alert("Ahoy " + ship.get("name") + "!");
+});
+
+var Ship = Backbone.Model.extend({});
+
+ships.add([
+ new Ship({name: "Flying Dutchman"}),
+ new Ship({name: "Black Pearl"})
+]);
+</pre>
+
+ <p id="Collection-remove">
+ <b class="header">remove</b><code>collection.remove(models, [options])</code>
+ <br />
+ Remove a model (or an array of models) from the collection. Fires a
+ <tt>"remove"</tt> event, which you can pass <tt>{silent: true}</tt>
+ to suppress.
+ </p>
+
+ <p id="Collection-get">
+ <b class="header">get</b><code>collection.get(id)</code>
+ <br />
+ Get a model from a collection, specified by <b>id</b>.
+ </p>
+
+ <p id="Collection-getByCid">
+ <b class="header">getByCid</b><code>collection.getByCid(cid)</code>
+ <br />
+ Get a model from a collection, specified by client id. The client id
+ is the <tt>.cid</tt> property of the model, automatically assigned whenever
+ a model is created. Useful for models which have not yet been saved to
+ the server, and do not yet have true ids.
+ </p>
+
+ <p id="Collection-at">
+ <b class="header">at</b><code>collection.at(index)</code>
+ <br />
+ Get a model from a collection, specified by index. Useful if your collection
+ is sorted, and if your collection isn't sorted, <b>at</b> will still
+ retrieve models in insertion order.
+ </p>
+
+
+
+
+
+
+
<h2 id="changes">Change Log</h2>
diff --git a/test/collection.js b/test/collection.js
index 67aa1ba..84921aa 100644
--- a/test/collection.js
+++ b/test/collection.js
@@ -35,11 +35,6 @@ $(document).ready(function() {
equals(col.getByCid(col.first().cid), col.first());
});
- test("collections: getIds, getCids", function() {
- equals(col.getIds().sort().join(' '), '1 2 3 4');
- equals(col.getCids().sort().join(' '), 'c1 c2 c3 c4');
- });
-
test("collections: at", function() {
equals(col.at(2), b);
});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/backbone.git
More information about the Pkg-javascript-commits
mailing list