Created
January 24, 2013 02:52
-
-
Save phungnc/4617280 to your computer and use it in GitHub Desktop.
Get Ideas from this:
http://stackoverflow.com/questions/9781102/backbone-multiple-collections-fetch-from-a-single-big-json-file
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
//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