Created
March 15, 2014 20:12
-
-
Save mgronhol/9573244 to your computer and use it in GitHub Desktop.
Fetch and parse multiple JSON datasets
This file contains hidden or 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
| function fetchMultiple( datasets, predicate, finished ){ | |
| var functions = []; | |
| var results = []; | |
| for( var i = 0 ; i < datasets.length ; ++i ){ | |
| functions.push( (function(i){ return function(){ | |
| $.getJSON( datasets[i], function( response ){ | |
| results.push( predicate( response ) ); | |
| functions[i+1](); | |
| }); | |
| }; })(i) ); | |
| } | |
| functions.push(function(){ | |
| finished( results ); | |
| }); | |
| functions[0](); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment