[Pkg-javascript-commits] [backbone] 141/281: #819 documenting idAttribute. Also requested on pull req #210.
Jonas Smedegaard
js at moszumanska.debian.org
Sat May 3 17:02:05 UTC 2014
This is an automated email from the git hooks/post-receive script.
js pushed a commit to tag 0.9.0
in repository backbone.
commit 570156914d540177e35967f36e3e934e0fbec944
Author: Irene Ros <irene at bocoup.com>
Date: Mon Dec 26 15:00:02 2011 -0500
#819 documenting idAttribute. Also requested on pull req #210.
---
index.html | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/index.html b/index.html
index c9d5f29..d25868b 100644
--- a/index.html
+++ b/index.html
@@ -684,7 +684,30 @@ if (note.has("title")) {
Models can be retrieved by id from collections, and the id is used to generate
model URLs by default.
</p>
+
+ <p id="Model-idAttribute">
+ <b class="header">idAttribute</b><code>model.idAttribute</code>
+ <br />
+ By default a model assumes its unique identifier is stored
+ under the <b>id</b> attribute.
+ In certain situations, for example when using CouchDB where the
+ identifying attribute is called <b>_id</b>, overwriting the property
+ name is necessary.
+ Setting the <b>idAttribute</b> during a model definition will
+ set the model's <b>id</b> to the value of the idAttribute property
+ instead. When referencing the model's <b>id</b>, continue
+ using <b>model.id</b>.
+
+<pre class="runnable">
+var Meal = Backbone.Model.extend({
+ idAttribute: "_id"
+});
+var cake = new Meal({ _id: 1, name: "Cake" });
+alert("Cake id: " + cake.id);
+</pre>
+ </p>
+
<p id="Model-cid">
<b class="header">cid</b><code>model.cid</code>
<br />
--
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