JSFiddle - React, Tailwind, and code Playground
by Gert Vaartjes
JavaScript
// overwrite Jquery Ajax
/*$.ajax = function(obj) {
console.log(obj.url);
var result = [1,2,3];
obj.success(result);
};*/
//$.ajax({url:'http:/gert', success: function(data) {console.log(data);}});
$.ajax({
type: "GET",
url: 'http://localhost:8080/highcharts-cloud-api-web/highcharts/option/dump.json',
async: false,
dataType: "json",
success: function (data) {
buildDictionary(data);
}
});
function buildDictionary(data) {
var parents = {},
main = [],
option,
name,
parent;
for (var idx = 0; idx < data.length; idx++) {
option = data[idx];
name = option.name;
// Get Parent Options, fail on main options
if (!/--/.test(name) && /-/.test(name) && !parents[name]) {
parents[name] = [option];
continue;
}
// Store main options
if (!/-/.test(name)) {
main.push(option);
}
// we have a child!
parent = name.split('--')[0];
if (parents.hasOwnProperty(parent)) {
if (/options3d/.test(name)) {
debugger;
}
parents[parent].push(option);
} else {
if (/options3d/.test(name)) {
debugger;
}
parents[parent] = [option];
}
}
console.log(parents);
console.log(main);
};