Skip to content

Instantly share code, notes, and snippets.

@phungnc
Created January 24, 2013 02:52
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 phungnc/4617280 to your computer and use it in GitHub Desktop.
Save phungnc/4617280 to your computer and use it in GitHub Desktop.
//Put your real collection constructors here. Just examples.
var collections = {
Languages: Backbone.Collection.extend(),
ProductTypes: Backbone.Collection.extend(),
Menus: Backbone.Collection.extend()
};
function fetch() {
$.getJSON("/url/to/your/big.json", {
success: function (response) {
for (var name in collections) {
//Grab the list of raw json objects by name out of the response
//pass it to your collection's constructor
//and store a reference to your now-populated collection instance
//in your collection lookup object
collections[name] = new collections[name](response[name]);
}
}
});
}
fetch();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment