Angular Ui tree increment duplicates

My plunker

In My plunker, if I add some children, then if I delete one of the children, then if I add rows, the rows will be duplicated.

$scope.newSubItem = function(scope) {
  var nodeData = scope.$modelValue;
  nodeData.items.push({
    id: nodeData.id * 10 + nodeData.items.length,
    rowId: nodeData.rowId + '.' + (nodeData.items.length + 1),
    items: []
  });
};
+3
source share
1 answer

Instead of adding nodeData.items.lenght add this for id

id: nodeData.items.length?(nodeData.items[nodeData.items.length-1].id)+1:nodeData.id * 10

And for rowId add this

 rowId: nodeData.rowId + '.' + ((nodeData.items.length?(parseInt(nodeData.items[nodeData.items.length-1].rowId.split('.').pop()))+1:0)),
+2
source

Source: https://habr.com/ru/post/1683141/


All Articles