当前位置: 首页 > news >正文

angular-tree-component组件中实现特定节点自动展开

核心API 都在 expandToNode这个函数中

HTML

treeData的数据结构大概如下

[{"key": "3293040275","id": "law_category/3293040275","name": "嘿嘿嘿嘿","rank": 0,"parentKey": "0","parentName": null,"rule": "","data": null,"children": [{"key": "3293069168","id": "law_category/3293069168","name": "哈哈哈哈","rank": 1,"parentKey": "3293040275","parentName": null,"rule": "","data": null,"children": []}]},{"key": "3293069383","id": "law_category/3293069383","name": "呵呵呵呵","rank": 0,"parentKey": "0","parentName": null,"rule": "","data": null,"children": []}
]
<tree-root#tree[nodes]="treeData"[options]="options"
><ng-template #treeNodeTemplate let-node let-index="index"><span>{{ node.data.name }}</span></ng-template>
</tree-root>

JS

getTree是获取树的数据 treeNodeId是要展开节点的Id
setTimeout是为了先让树渲染出来 然后再进行节点选择

import { ViewChild } from "@angular/core";
import { TreeComponent } from "@circlon/angular-tree-component";@ViewChild("tree") tree: TreeComponent;options = {displayField: "nodeName",// isExpandedField: "expanded",// idField: "uuid",hasChildrenField: "nodes",// actionMapping: {//   mouse: {//     dblClick: (tree, node, $event) => {//   		if (node.hasChildren) TREE_ACTIONS.TOGGLE_EXPANDED(tree, node, $event);// 		}//   },//   keys: {//     [KEYS.ENTER]: (tree, node, $event) => {//       node.expandAll();//     }//   }// },allowDrag: (node) => {return true;},allowDrop: (node) => {return true;},allowDragoverStyling: true,levelPadding: 10,useVirtualScroll: true,animateExpand: true,scrollOnActivate: true,animateSpeed: 30,animateAcceleration: 1.2,scrollContainer: document.documentElement, // HTML
};// 获取树结构 getTree是获取树的数据  treeNodeId是要展开节点的Idthis.LawsService.getTRee().subscribe((data) => {this.treeData = data?.data;console.log(this.treeData);setTimeout(() => {this.expandToNode(treeNodeId);}, 0);});
expandToNode(nodeId: string) {const treeModel = this.tree.treeModel;const targetNode = treeModel.getNodeById(nodeId);if (targetNode) {targetNode.ensureVisible();treeModel.setActiveNode(targetNode, { noEvent: true, noFocus: true });}
}
http://www.lryc.cn/news/286092.html

相关文章:

  • Linux系统下安装Vcpkg,并使用Vcpkg安装、编译OpenSceneGraph
  • 设计模式二(工厂模式)
  • Maven应用手册
  • 笨蛋学设计模式行为型模式-状态模式【20】
  • C++从零开始的打怪升级之路(day18)
  • 浅谈安科瑞直流电表在新加坡光伏系统中的应用
  • C++参悟:数值运算相关
  • 【Web前端开发基础】CSS的定位和装饰
  • [pytorch入门] 3. torchvision中的transforms
  • WINCC读写EXCEL-VBS
  • Python os模块
  • Elasticsearch:2023 年 Lucene 领域发生了什么?
  • Java算法 leetcode简单刷题记录4
  • opencv#27模板匹配
  • 【论文阅读笔记】Swin-Unet: Unet-like Pure Transformer for Medical Image Segmentation
  • IS-IS:01 ISIS基本配置
  • 基于极限学习机的曲线分类,基于极限学习机的光谱分类,基于极限学习机的分类预测
  • miniconda安装
  • PHP判断访客是否手机端(移动端浏览器)访问的方法总结
  • vscode无法自动补全
  • 深度学习记录--指数加权平均
  • 如何生成图源二维码?
  • PowerShell install 一键部署grafana
  • 笨蛋学设计模式行为型模式-解释器模式【23】
  • SAP ABAP SUBMIT常用用法
  • GitLab备份与恢复测试(基于Docker)
  • android studio开发的一些问题
  • 辞职对于我来说,不可避免(10)
  • 【Java】--网络编程:基于TCP协议的网络通信
  • CMake+QT+大漠插件的桌面应用开发(QThread)