d3.js - How to wait on d3.json to finish? -


how can wait d3.json fill array saved_data before function callback executed?

i'm using saved_data if not empty. otherwise i'm requesting new data , saving in saved_data variable:

if (saved_data.length > 0) {   callback(null, parse(variable, saved_data));  } else {   // -------------- begin request new data ------------------   d3.json(" ... ",        function(data) {         if (!data) return callback(new error("unable load data"));            saved_data = data;    });    // how wait on d3.json? before call back?   callback(null, parse(variable, saved_data));  } 

if (saved_data.length > 0) {   callback(null, parse(variable, saved_data));  } else { // -------------- begin request new data ------------------   d3.json(" ... ",        function(data) {         if (!data) return callback(new error("unable load data"));            saved_data = data;          // put here.         callback(null, parse(variable, saved_data));       }); }  

put in same callback d3.json


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -