Passing JSON object as data source
Passing JSON object as data source
Hi, everyone:
I've been poking around online for an answer to this question but haven't been able to find one.
A lot of the data tables I build use a JSON object stored in a .js file as a data source. Like this:
[code][
["AK","Anchorage"," 291,826 ","40.1%","39.9%"," 0.2 "],
["AL","Auburn"," 53,380 ","55.6%","59.1%"," -3.5 "],
... more ...
][/code]
However, to get them to work, I've had to change the files to variable declarations and bring them in as scripts like this:
[code]tabledata = [
["AK","Anchorage"," 291,826 ","40.1%","39.9%"," 0.2 "],
["AL","Auburn"," 53,380 ","55.6%","59.1%"," -3.5 "],
... more ...
];[/code]
Then I just set aaData to this variable name to marry the JSON data to the data table.
I am guessing this is not the best or most efficient way to handle this, particularly since it means modifying a valid JSON file. But I haven't been able to figure out another way to bring in the data. If someone could point me in the right direction, I'd really appreciate it. For what it's worth the JSON file is in the same directory as the .html file.
Thank you,
chris
I've been poking around online for an answer to this question but haven't been able to find one.
A lot of the data tables I build use a JSON object stored in a .js file as a data source. Like this:
[code][
["AK","Anchorage"," 291,826 ","40.1%","39.9%"," 0.2 "],
["AL","Auburn"," 53,380 ","55.6%","59.1%"," -3.5 "],
... more ...
][/code]
However, to get them to work, I've had to change the files to variable declarations and bring them in as scripts like this:
[code]tabledata = [
["AK","Anchorage"," 291,826 ","40.1%","39.9%"," 0.2 "],
["AL","Auburn"," 53,380 ","55.6%","59.1%"," -3.5 "],
... more ...
];[/code]
Then I just set aaData to this variable name to marry the JSON data to the data table.
I am guessing this is not the best or most efficient way to handle this, particularly since it means modifying a valid JSON file. But I haven't been able to figure out another way to bring in the data. If someone could point me in the right direction, I'd really appreciate it. For what it's worth the JSON file is in the same directory as the .html file.
Thank you,
chris
This discussion has been closed.
Replies
Allan
chris