我正在尝试制作一棵复选框树,我正在使用 Angular 和 Firestore 数据库。父节点和子节点与子文档中的引用相关,因此在实现此树时,我必须加载父节点并按需异步获取子节点。
现在我正在测试@circlon/angular-tree-component
,但是当点击父节点时,即使加载了异步子节点也没有显示getChildren
,我只能看到加载...
这是我的代码:
options: ITreeOptions = {
getChildren: this.getChildren.bind(this),
useCheckbox: true
};
nodes: any[] = [];
constructor(private childrenService: ChildrenService,
private parentService: ParentService) {
this.parentService.getAll(true, (ref) => ref.where('active', '==', true))
.pipe(map(e => {
return e.map(l => {
l['hasChildren'] = true;
l['name'] = l.title;
return l;
})
}))
.subscribe(data => {
data.forEach(e => {
this.nodes.push(e);
})
});
}
getChildren(node: TreeNode) {
return this.childService.getChildren(node.id)
.pipe(map(e => {
return e.map(l => {
l['name'] = l.firstName;
l['hasChildren'] = false;
return l;
})
})).toPromise();
}
<div *ngIf="nodes.length !=0">
<tree-root #tree [options]="options" [nodes]="nodes"></tree-root>
</div>