Angular checkboxes in tree view

前端 未结 1 771
面向向阳花
面向向阳花 2021-01-14 17:41

I could not find a really good suitable directive for creating a tree view with checkboxes from a JSON-structure, so I did this with a self-calling iterator, as seen here:

相关标签:
1条回答
  • 2021-01-14 17:59

    I would preprocess the tree data in a recursive way similar to your setData function:

     function initTree(tree) {
       function processNode(node) {
         angular.forEach(node.children, function(child) {
           if(processNode(child) === true) {
             node.chk = true;   
           }
         });
    
         return node.chk;
       }
    
       angular.forEach(tree, processNode);
     };
     initTree($scope.tree);
    

    See updated fiddle http://jsfiddle.net/65yucqge/

    Edit Here is another fiddle showing how to get the checkbox data into an array: http://jsfiddle.net/tmakin/kmhw1ue0/

    0 讨论(0)
提交回复
热议问题