This commit is contained in:
2019-09-16 20:36:30 -06:00
commit 33714c6291
12 changed files with 749 additions and 0 deletions

26
hw2/js/script.js Normal file
View File

@@ -0,0 +1,26 @@
/**
* Requests the file and executes a callback with the parsed result once
* it is available
* @param {path} file path
* @param {callback} callback to execute once the result is available
*/
function fetchJSONFile(path, callback) {
var httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function() {
if (httpRequest.readyState === 4) {
if (httpRequest.status === 200) {
let data = JSON.parse(httpRequest.responseText);
if (callback) callback(data);
}
}
};
httpRequest.open('GET', path);
httpRequest.send();
}
//call fetchJSONFile then build and render a tree
fetchJSONFile('data/Tree.json', function(data) {
let tree = new Tree(data);
tree.buildTree();
tree.renderTree();
});