mirror of
https://github.com/jashkenas/backbone.git
synced 2026-04-30 03:00:06 -04:00
Merge pull request #2386 from tgriesser/doc-custom-constructor
Adding custom constructor example code.
This commit is contained in:
13
index.html
13
index.html
@@ -956,6 +956,19 @@ new Book({
|
||||
you to replace the actual constructor function for your model.
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
var Library = Backbone.Model.extend({
|
||||
constructor: function() {
|
||||
this.books = new Books();
|
||||
Backbone.Model.apply(this, arguments);
|
||||
},
|
||||
parse: function(data, options) {
|
||||
this.books.reset(data.books);
|
||||
return data.library;
|
||||
}
|
||||
});
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
If you pass a <tt>{collection: ...}</tt> as the <b>options</b>, the model
|
||||
gains a <tt>collection</tt> property that will be used to indicate which
|
||||
|
||||
Reference in New Issue
Block a user