Skip to content

Instantly share code, notes, and snippets.

@mgronhol
Created March 15, 2014 20:12
Show Gist options
  • Select an option

  • Save mgronhol/9573244 to your computer and use it in GitHub Desktop.

Select an option

Save mgronhol/9573244 to your computer and use it in GitHub Desktop.
Fetch and parse multiple JSON datasets
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