Best approach to create recursive treeview dynamically from data API

后端 未结 1 1537
孤独总比滥情好
孤独总比滥情好 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: `
            
    `, directives: [TreeView] }) export class TreeView { @Input() private dirs: Array; }

    I hope you will like it.

    Cheers!

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