This is a challenging task for an AngularJS newbie like me so I would like to ask some help or assistance. So what I want to achieve is to group the data via tree level and tree id.
My current code for the HTML:
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
  <div ng-app="myApp" ng-controller="myCtrl">
      <ul>
          <li ng-repeat="item in list">
              [[ item.code ]]
          </li>
      </ul>
  </div>
</body>
</html>
My current code for the JS:
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
    $scope.list = [
        {
            "id": 1,
            "code": "TANK",
            "tree_id": 1,
            "level": 0,
            "parent": null
        },
        {
            "id": 2,
            "code": "OIL",
            "tree_id": 1,
            "level": 1,
            "parent": 1
        },
        {
            "id": 3,
            "code": "CHEM",
            "tree_id": 1,
            "level": 1,
            "parent": 1
        },
        {
            "id": 6,
            "code": "PROD",
            "tree_id": 1,
            "level": 2,
            "parent": 3
        },
        {
            "id": 4,
            "code": "BULK",
            "tree_id": 2,
            "level": 0,
            "parent": null
        },
        {
            "id": 5,
            "code": "LOG",
            "tree_id": 2,
            "level": 1,
            "parent": 4
        }
    ],
});
If you checked the $scope.list, you can find the tree_id, level and parent. So what I really want to achieve is to group the objects via tree id then the level 0 or top level will be the one present while the level 1 and up will be just be a collapsible content. Please take that the tree_id serves as a groupings between the object, the level can be considered as their hierarchy order and heir hierarchy root will depend on the integer value of the parent which is a tree id. Also please be aware that this is not limited to one branch but multiple, flexible and unlimited branches
The render should look something like this:
- TANK
- CHEM
- OIL
- PROD
 
 
- BULK
- LOG
 
 
     
     
     
     
    