0

How to get the positions of nodes of TreeNode of pTree in Angular as per the hierarchial order in which they are displayed?

I am having data of type TreeNode and in the data I am also having children, branched children, any number of branching. How to access these nodes as per the hierarchial order, suppose child1 is a child of Children and Children is child to root 'Root'. So the position of child2 is="Root.Children.child1".

**export interface TreeNode {
label?: string;
child?: [TreeNode];
}**

1 Answers1

0
import { TreeNode } from 'primeng/api';

import TreeNode and use this as the type of variable, no need of interface.

treeData: TreeNode[]=[
        {
        "label": "Documents",
        "data": "Documents Folder",
        "expandedIcon": "fa fa-folder-open",
        "collapsedIcon": "fa fa-folder",
        "children": [{  
                       "label": "Documents 2",
                       "data": "Documents Folder 2",
                       "expandedIcon": "fa fa-folder-open",
                       "collapsedIcon": "fa fa-folder",
                       "children":[{ 'same format for any number 
                                      of childrens' }]
                    }]
        }]

using this format p-tree can be built with any number of child, for expanded and collapsed icon you can give any icon-class from prime-ng or icon-font-class. 'expanded':true; use this property to expand the node by default.

Harish
  • 104
  • 6