mirror of
https://github.com/jashkenas/backbone.git
synced 2026-01-14 17:37:54 -05:00
Merge pull request #2350 from hshoff/polymorphic
add documentation about collections containing polymorphic models. Fixes...
This commit is contained in:
19
index.html
19
index.html
@@ -1493,6 +1493,25 @@ bill.set({name : "Bill Jones"});
|
||||
var Library = Backbone.Collection.extend({
|
||||
model: Book
|
||||
});
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
A collection can also contain polymorphic models by overriding this property
|
||||
with a function that returns a model.
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
var Library = Backbone.Collection.extend({
|
||||
|
||||
model: function(attrs, options) {
|
||||
if (condition) {
|
||||
return new PublicDocument(attrs, options);
|
||||
} else {
|
||||
return new PrivateDocument(attrs, options);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
</pre>
|
||||
|
||||
<p id="Collection-constructor">
|
||||
|
||||
Reference in New Issue
Block a user