Looking to efficiently clone nodes in an Angular UI tree along with all their children?
I currently have an event click setup like this: ng-click="newSubItem(this)"
, where the function newSubItem
is as follows:
$scope.newSubItem = function (scope) {
var nodeData = scope.$modelValue;
var childNodes = [];
angular.forEach(nodeData.nodes, function (value) {
childNodes.push(value);
});
var totalNodes = nodeData.nodes.length;
var prefixIncrement = totalNodes + 1;
nodeData.nodes.push({
id: nodeData.id + prefixIncrement,
prefix: nodeData.prefix + "_" + prefixIncrement,
title: nodeData.title + '.' + (nodeData.nodes.length + 1),
value: nodeData.value,
type: nodeData.type,
nodes: childNodes
});
};
However, when attempting to insert all children from the cloned object into the new nodes: nodes: childNodes
, it leads to numerous errors and disrupts the tree's structure.