iVantage / angular-ivh-treeview

A treeview for AngularJS with filtering and checkbox support.
http://ivantage.github.io/angular-ivh-treeview/
MIT License
238 stars 89 forks source link

capture only the leaf nodes when the parent node gets selected in angular-ivh-treeview #182

Closed JavaCodeStream closed 7 years ago

JavaCodeStream commented 7 years ago

Cross Posting: SO post: http://stackoverflow.com/questions/43710477/capture-only-the-leaf-nodes-when-the-parent-node-gets-selected-in-angular-ivh-tr

managed to implement almost everything that I wanted with the treeview but could not able to capture only the leaf nodes whenever the parent node getting selected, So I only need the leaf node objects to be added on my array of selected nodes at any type of selections like below:

case 1: on selection of a leaf node

case 2: on selection of the immediate parent node of a set of leaf nodes

case 3: on selection of the last left leaf node etc... etc..

<div ivh-treeview="demo.stuff"
     ivh-treeview-expand-to-depth="-1"
     ivh-treeview-on-cb-change="demo.updateSelection()">
</div>

$scope.demo.updateSelection = function() {
    $scope.selectedNodes.length = 0;
        ivhTreeviewBfs($scope.demo.stuff, function(node) {
          if(node.selected) {
              $scope.selectedNodes.push(node);
          }
    });  
}

With these above code, the entire hierarchy is getting added into my selected nodes array as soon as the parent node gets selected.

jtrussell commented 7 years ago

@JavaCodeStream Thanks - let's continue the conversation on SO :).