How to dynamically increase parent row in angular ui tree

Plunker.

In this plunter, I supported +and ++. +to increase parent rows and ++to increment child rows.

Here it ++increases correctly. and "+" also increase correctly, if I click on it ++, it will add one child line for the parent.

then, if I click the button +, it should add another child row for the parent. but he adds another main line.

Here I got a line with this keyword in html. How can I get the parent of the child string that we clicked on.

ng-click="newSubItem(this)"//here This keyword will give the current object.

controller: -

$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: []
      });
    };

[] array.so .

, .

+4
1

ok addParentRow

 $scope.addParentRow = function(scope) {

  if (scope.$nodeScope.$parentNodeScope) {
    var nodeData = scope.$nodeScope.$parentNodeScope.$modelValue
    nodeData.items.push({
      id: nodeData.id * 10 + nodeData.items.length,
      rowId: nodeData.rowId + '.' + (nodeData.items.length + 1),
      items: []
    });
  } else {
    var lastObj = $scope.list[$scope.list.length - 1];
    var rowItem = {
      "id": parseFloat(lastObj.id) + 1,
      "rowId": parseFloat(lastObj.rowId) + 1,
      "items": []
    }
    $scope.list.push(rowItem);
  }
}

Plunker

+4

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


All Articles