loadTree() {
this.auditItemTypeService
.findAllTree()
.pipe(
switchMap((result: Array<TreeDto>) => {
this.nodes = result;
if (result && result.length) {
// this.activeNode = this.nodes.find(item => {
// return item.key === this.activeNode.key;
// });
this.activeNode = this.findNode(this.nodes, this.currentItemId);
if (!this.activeNode) {
this.activeNode = this.nodes[0];
}
if (this.activeNode) {
this.activeNode.selected = true;
this.expandedKeys = [this.activeNode.key];
}
return this.auditItemTypeService.findById(this.activeNode.key);
} else {
this.activeNode = null;
return of(null);
}
}),
)
.subscribe(res => {
if (res) {
this.isLeaf = false;
this.auditItemTypeDetailComponent.edit(res);
this.isEdit = false;
}
});
}
rxjs switchmap 应用案例