-1

I have the following script:

var dataSet;
d3.json("/TableData", function(error, json) {
  if (error) return console.warn(error);
  dataSet = json;
});

$('#data-table').dynatable({
  dataset: {
    records: dataSet
  }
});

/TableData is a sqlalchemy call to a db which returns:

{
  "data": [
{
  "Type": "Turbine", 
  "Seconds": 170, 
}, 
{
  "Type": "Turbine", 
  "Seconds": 75435, 
}]}

I don't get any errors with the console but nothing shows up in the flask website? if I go to http://127.0.0.1/TableData I can see the table data.

KillerSnail
  • 3,321
  • 11
  • 46
  • 64
  • also on the mark as duplicate i didn't know what an asynchronous call was so couldn't find that answer in search – KillerSnail Jun 02 '16 at 01:07

1 Answers1

1

This is why because d3.json function is asynchronous and dataSet variable may be set only after the execution of dynatable code.

So try this way.

d3.json("/TableData", function(error, json) {
  if (error) return console.warn(error);
  var dataSet = json;
  $('#data-table').dynatable({
    dataset: {
       records: dataSet
    }
  });
});

You can confirm this by console logging the dataSet variable value from inside the d3.json callback function and outside the function.

Gilsha
  • 14,431
  • 3
  • 32
  • 47