4

Plunker.

In this plunker I have maintained + and ++. + for increment the parent rows and ++ for increment the child rows.

Here ++ is incrementing correctly. and '+' also incrementing correctly, if I click on ++ then it will add one child row for parent.

then if I click on + button for it should add another child row for parent. but it is adding another main row.

Here I got the perticular row with this keyword in html. Like that How can I get parent object of the child row what we have clicked.

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

Like this I want to increment the current object and push into the items[] array.so The current object will comes under parent object.

Finally how can I get the parent object of the current object.

2
  • your question is little ambiguous, you should add a + button for only main rows, and then the + button in the tree should add a child in that parent Commented Aug 7, 2017 at 5:43
  • let me add an answer if it doesn't fit your requirement then let me know Commented Aug 7, 2017 at 6:01

1 Answer 1

4

ok now update your addParentRow function with this only

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

Here is the Plunker

Sign up to request clarification or add additional context in comments.

2 Comments

have you found the problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.