Best approach to create recursive treeview dynamically from data API

后端 未结 1 1538
孤独总比滥情好
孤独总比滥情好 2021-02-06 08:36

I\'m learning Angular 2, trying to build an expandable tree-view from a (potentially very large) third-party API. The API has an underlying structure like this:



        
相关标签:
1条回答
  • 2021-02-06 09:24

    in Angular2 you can render directives recursively. This makes rendering the tree very easy. I've modified your Plunker a little bit just to show the point. It's not the ideal implementation but it works as expected :).

    Example:

    @Component({
        selector: 'tree-view',
        template: `
            <div *ngFor="#dir of dirs">
                <tree-view [dirs]="dir.dirs"></tree-view>
            <div>
        `,
        directives: [TreeView]
    })
    export class TreeView {
        @Input() 
        private dirs: Array<Directory>;
    }
    

    I hope you will like it.

    Cheers!

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