Last active
October 25, 2018 20:47
-
-
Save alexfinnarn/f10a9c7ca50cd9ce0af99cf6c89bfcfa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get headers from input. | |
orgLevelHeaders = document.getElementById('org_level_headers').value.split(','); | |
// Cut the data headers from the levels. | |
// Length will be the number of columns needed to determine hierarchy. | |
const dataHeaders = results.meta.fields.splice(orgLevelHeaders.length); | |
let varString = 'finalData'; | |
results.data.forEach(function (el, index) { | |
for (i = 0; i < orgLevelHeaders.length; i++) { | |
// If header value is blank, then it is a parent of something. | |
if (el[orgLevelHeaders[i]] === '') { | |
eval(varString + " = {}"); | |
eval(varString + ".data = {}"); | |
eval(varString + ".children = {}"); | |
// Gather data. | |
let data = {}; | |
dataHeaders.forEach(function (header, ind) { | |
data[header] = el[header]; | |
}); | |
eval(varString + ".data = " + JSON.stringify(data) + ';'); | |
break; | |
} | |
// If it isn't blank, then add it to the variable string. | |
varString += '.children["' + el[orgLevelHeaders[i]] + '"]'; | |
} | |
varString = 'finalData'; | |
} | |
downloadFile(finalData); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment