Last active
December 18, 2015 14:28
-
-
Save dspangen/5797361 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var NestedCollection = Backbone.Collection.extend({ | |
// Takes parent and nestedPath, corresponding to the parent | |
// of this nested collection, and the name of the nested | |
// resource to be used in the url for this collection. | |
initialize: function(undefined, options) { | |
Backbone.Collection.prototype.initialize.apply(this, arguments); | |
this.parent = options && options.parent; | |
if ( !this.parent || ! this.nestedPath ) { | |
throw "a parent model, corresponding to the parent of this Nested, " + | |
"must be provided at initialization, as well as the nestedPath"; | |
} | |
}, | |
// Uses the path of the parent to generate the url for this | |
// nested collection. | |
url: function() { | |
return _.result(this.parent, "url") + "/" + nestedPath; | |
} | |
}); | |
var PagedNestedCollection = NestedCollection.extend({ | |
// paging implementation | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment