Skip to content

Instantly share code, notes, and snippets.

@RickButler
Last active January 12, 2016 14:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RickButler/0924c7a96617187995e6 to your computer and use it in GitHub Desktop.
Save RickButler/0924c7a96617187995e6 to your computer and use it in GitHub Desktop.
A helper method for an ampersand-view / ampersand-model to fetch the children if they have a url and fetch method.
var View = require('ampersand-view'); // you can use ampersand-model/ampersand-state here too
var _ = require('lodash');
module.exports = View.extend({
fetchChildren: function(options) {
_.chain(this._children)
.keys()
.each(function(key) {
if(_.isFunction(this[key].url) && _.isFunction(this[key].fetch) {
this[key].fetch(options);
}
}, this);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment