rxjs switchmap 应用案例

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 应用案例

上一篇:html元素是如何占据空间和定位的


下一篇:记一次使用RestHighLevelClient连接ElasticSearch 7.12.0 https 域名遇到的坑