Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular Ui tree incrementing is duplicating

My Plunker.

In My plunker if I add some childs, then if I remove one of child record then if I add rows the rows are duplicating.

$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: []
  });
};
like image 292
Murali Avatar asked Mar 07 '26 09:03

Murali


1 Answers

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)),
like image 166
Ghulam Mohayudin Avatar answered Mar 08 '26 22:03

Ghulam Mohayudin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!