0

I use plugin Angular UI Tree:

http://angular-ui-tree.github.io/angular-ui-tree/#/basic-example

<a class="pull-right btn btn-primary btn-xs" data-nodrag="" ng-click="newSubItem(this)" style="margin-right: 8px;"><span class="glyphicon glyphicon-plus"></span></a>

I use this code:

$scope.newSubItem = function (scope) {

            var nodeData = scope.$modelValue;
            var arrr_nodes = [];

            angular.forEach(nodeData.nodes, function (value) {
                arrr_nodes.push(arrr_nodes);
            });

            var total_nodes = nodeData.nodes.length;
            var prefix_increment = total_nodes + 1;

            nodeData.nodes.push({
                id: nodeData.id + prefix_increment,
                prefix: nodeData.prefix + "_" + prefix_increment,
                title: nodeData.title + '.' + (nodeData.nodes.length + 1),
                value: nodeData.value,
                type: nodeData.type,
                nodes: []
            });
        };
georgeawg
  • 48,608
  • 13
  • 72
  • 95
Yahorow
  • 51
  • 8
  • Problem is that when I do: `nodes: [] = node Data.nodes ` it invoke error, because nodes Data.nodes contains duplicates. – Yahorow Jun 12 '17 at 19:38
  • I think solution in another post is not working, cause it clones all nodes with the same id, it calls an error – Yahorow Jun 12 '17 at 19:51

0 Answers0