Reputation: 181
I'm using https://github.com/dotJEM/angular-tree as a recursive directive to loop through this kind of model :
$scope.model = [
{
label: 'parent1',
children: [{
label: 'child'
}]
},
{
label: 'parent2',
children: [{
label: 'child',
children: [{
label: 'innerChild'
}]
}]
},
{
label: 'parent3'
}
];
In the template, the code looks like this:
<div data-dx-start-with="model">
<div data-ng-repeat="node in $dxPrior">
<a class="list-group-item">
<span class="icon" data-ng-click="toggle(node)"><i class=" icon ion-android-arrow-dropdown"></i> </span>
<span>{{ node.label}} ({{node.children.length}})</span>
</a>
<ul data-ng-show="node.expanded" data-dx-connect="node.children"></ul>
</div>
</div>
Now, how would I go about accessing each parent? I want to be able to build a breadcrumb of the treeview.
Ex : parent2 > child > innerChild > ...
I can get each node's parent by using $parent if I'm not mistaken... but how would I go about getting each parent(s)?
I have created a plnkr to illustrate : http://plnkr.co/edit/DOc9k4jT9iysJLFvvg3u?p=preview
Upvotes: 0
Views: 463
Reputation: 289
Just program it. Make function that will walk thru parents until reach the root and construct array of parents in each step:
$scope.getParentsBreadcrumb = function (thisScope) {
var parents = [];
while (thisScope && thisScope.node) {
parents.unshift (thisScope.node.label);
thisScope = thisScope.$parent.$parent;
}
return parents.join(' > ')
}
Then call it in your template where you want to print breadcrumbs:
{{getParentsBreadcrumbs (this)}}
Upvotes: 1