From 9f35e897483457fefda36ee51ca274185873afeb Mon Sep 17 00:00:00 2001 From: "holger.trampe" Date: Thu, 26 Mar 2020 22:52:02 +0100 Subject: [PATCH] organigramm test --- orga/templates/orga/orga_main.html | 59 ++++++++++++++++-------------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/orga/templates/orga/orga_main.html b/orga/templates/orga/orga_main.html index 6117ffd..57bae70 100644 --- a/orga/templates/orga/orga_main.html +++ b/orga/templates/orga/orga_main.html @@ -17,8 +17,11 @@ @@ -56,38 +59,41 @@ for(i = 0; i < data.length; i++){ } } + + + + //Creates nested array from data function unflatten(arr) { - var tree = [], - mappedArr = {}, - arrElem, - mappedElem; + var tree = [], + mappedArr = {}, + arrElem, + mappedElem; - // First map the nodes of the array to an object -> create a hash table. - for(var i = 0, len = arr.length; i < len; i++) { - arrElem = arr[i]; - mappedArr[arrElem.id] = arrElem; - mappedArr[arrElem.id]['children'] = []; - } + // First map the nodes of the array to an object -> create a hash table. + for(var i = 0, len = arr.length; i < len; i++) { + arrElem = arr[i]; + mappedArr[arrElem.id] = arrElem; + mappedArr[arrElem.id]['children'] = []; + } - for (var id in mappedArr) { - if (mappedArr.hasOwnProperty(id)) { - mappedElem = mappedArr[id]; - // If the element is not at the root level, add it to its parent array of children. - if (mappedElem.parent) { - mappedArr[mappedElem['parent']]['children'].push(mappedElem); - } - // If the element is at the root level, add it to first level elements array. - else { - tree.push(mappedElem); - } - } + for (var id in mappedArr) { + if (mappedArr.hasOwnProperty(id)) { + mappedElem = mappedArr[id]; + // If the element is not at the root level, add it to its parent array of children. + if (mappedElem.parent) { + mappedArr[mappedElem['parent']]['children'].push(mappedElem); + } + // If the element is at the root level, add it to first level elements array. + else { + tree.push(mappedElem); } - return tree; } + } + return tree; +} var html = ['