question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

tree.treeModel.roots returns []

See original GitHub issue

I want to collapse, expand roots after initialization.

I have initialized a tree with 1 root, which has several children. I have defined the tree as a ViewChild, and after console.logging the tree I can see in the console, that roots in treeModel is an array of length 1. But after console.logging tree.treeModel.roots I get empty array.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
adamkleingitcommented, Sep 27, 2016

I’m assuming you initialize reports with an empty array, and only later initialize it with data? You have 3 options:

  1. Use *ngIf to show tree only if reports has data
  2. Initialize reports with null instead of empty array.
  3. Use onUpdateData event instead of onInitialized (notice that every time you update the pointer to reports this event will fire)

On Tue, Sep 27, 2016 at 12:34 PM, Alexander Ciesielski < notifications@github.com> wrote:

html

<div class="report-tree-container"> <Tree #reportsTree [nodes]="reports" (onInitialized)="onTreeInitialized($event)" (onActiveChanged)="onActiveChanged($event)"> </Tree> </div>

ts

@ViewChild(‘reportsTree’) reportsTree: TreeComponent; @Input() reports: ReportTreeNode[];

onTreeInitialized() { console.log(this.reportsTree.treeModel); console.log(this.reportsTree.treeModel.roots); }

export interface ReportTreeNode { name: string;

id?: number;
children?: ReportTreeNode[];

}

Same result as above

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/500tech/angular2-tree-component/issues/58#issuecomment-249815190, or mute the thread https://github.com/notifications/unsubscribe-auth/AA2SSm-zDXYQT_D8OvVmb6a2cUQjJv9gks5quOMQgaJpZM4KDwaa .

0reactions
alexciesielskicommented, Sep 27, 2016

reports is initialized by parent component with async pipe.

<app-report-list [reports]="reports | async" (select)="selectReport($event)">
</app-report-list>

Using onUpdateData instead of onInitialized fixed the issue, makes sense! Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

tree.treeModel.roots returns [] · Issue #58 - GitHub
I want to collapse, expand roots after initialization. I have initialized a tree with 1 root, which has several children.
Read more >
TreeModel (Java SE 17 & JDK 17) - Oracle Help Center
Returns the root of the tree. Returns null only if the tree has no nodes. Returns: the root of the tree. getChild. Object ......
Read more >
angular tree component expand after loading data
When you update your nodes you need to listen to the updateData Event. <tree-root [nodes]="nodes" (updateData)="onUpdateData()"></tree-root> ...
Read more >
TreeModel
Manipulate and traverse tree-like structures in javascript. ... var node12 = root.first(function (node) { return node.model.id === 12; }); ...
Read more >
Simple Tree Model Example | Qt Widgets 6.4.1
The Simple Tree Model example shows how to use a hierarchical model with Qt's ... root item in the model will not have...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found