I have a tree structure like this stored in the $scope.tree object. I want to create a filter, that I could apply to this tree to shrink it to this to be able to do smth like this $scope.cut_tree = $filter('cutTree')($scope.tree) and get that minified output.
But I have really no idea how to do that, everything I've tried so far does not get me anywhere, 'cause I end up changing the $scope.tree itself.
UPDATE
What I have so far:
app.filter("filterTree", ["$filter", function($filter) {
return function(tree) {
var newTree = [];
angular.forEach(tree, function(node, index) {
var newNode;
newNode = {
id: node.id,
sort_order: index,
children: $filter('filterTree')(node.children)
};
newTree.push(newNode);
});
return newTree;
};
}
]);
var treeCopy = angular.copy(tree);)