diff --git a/src/backend/InvenTree/templates/js/dynamic/nav.js b/src/backend/InvenTree/templates/js/dynamic/nav.js index 4f5c73d328..bec8d208cf 100644 --- a/src/backend/InvenTree/templates/js/dynamic/nav.js +++ b/src/backend/InvenTree/templates/js/dynamic/nav.js @@ -163,7 +163,13 @@ function generateTreeStructure(data, options) { const nodes = {}; const roots = []; - for (let node of data) { + if (!data || !Array.isArray(data) || data.length == 0) { + return []; + } + + for (let ii = 0; ii < data.length; ii++) { + let node = data[ii]; + nodes[node.pk] = node; node.selectable = false; @@ -173,12 +179,16 @@ function generateTreeStructure(data, options) { }; if (options.processNode) { - data[data.indexOf(node)] = options.processNode(node); + node = options.processNode(node); + data[ii] = node; } } - for (let node of data) { - if (node.parent != null) { + for (let ii = 0; ii < data.length; ii++) { + + let node = data[ii]; + + if (!!node.parent) { if (nodes[node.parent].nodes) { nodes[node.parent].nodes.push(node); } else { @@ -186,9 +196,9 @@ function generateTreeStructure(data, options) { } if (node.state.expanded) { - while (node.parent != null) { + while (!!node.parent) { nodes[node.parent].state.expanded = true; - data[data.indexOf(node)] = nodes[node.parent]; + node = nodes[node.parent]; } }