angular - 如何使用嵌套数据扩展角度材料树中的嵌套节点?
问题描述
我在我的 Angular 7 应用程序中使用带有嵌套对象数据数组的 mat 树。我想在用户对嵌套部分数据进行一些更改后扩展嵌套部分。
我有大量对象,我可以展开第一级树节点,但无法展开嵌套部分。
例如,我的节号为 9.2.1.2,所以在这种情况下,我必须扩展节号为 9、9.2、9.2.1 和 9.2.1.2 的节。怎么做?下面是数组中的示例对象
{
"sectionNum": 6,
"title": "ETHICS AND REGULATORY APPROVAL",
"csrSectionNum": "5",
"templateDTO": {
"sectionNum": 89,
"title": "ETHICS AND REGULATORY APPROVAL",
"csrSectionNum": "5",
"parent": "0",
"sequence": 1,
"active": 1,
"subReportTypeId": 2,
"sectionType": "3",
"isHighlightSection": 0,
"children": [],
"contents": null
},
"isDefault": 1,
"parent": "0",
"sequence": 1,
"sectionType": "3",
"active": 1,
"studyId": 2,
"version": 0,
"userId": 0,
"createdDate": "2021-04-03 10:03:18",
"isHighlightSection": 0,
"sectionIdentifiedPercentage": "100",
"isBookmarked": false,
"children": [
{
"sectionNum": 7,
"title": "INDEPENDENT ETHICS COMMITTEE APPROVAL",
"csrSectionNum": "5.1",
"templateDTO": {
"sectionNum": 90,
"title": "INDEPENDENT ETHICS COMMITTEE APPROVAL",
"csrSectionNum": "5.1",
"parent": "5",
"sequence": 1,
"active": 1,
"subReportTypeId": 2,
"sectionType": "4",
"isHighlightSection": 0,
"children": [],
"contents": null
},
"isDefault": 1,
"parent": "5",
"sequence": 1,
"sectionType": "4",
"active": 1,
"studyId": 2,
"version": 0,
"userId": 0,
"createdDate": "2021-04-03 10:03:18",
"isHighlightSection": 0,
"sectionIdentifiedPercentage": "100",
"isBookmarked": false,
"children": [],
"contents": null,
"sfdtContent": null,
"keywordInput": false
},
{
"sectionNum": 8,
"title": "ETHICAL CONDUCT OF THE STUDY",
"csrSectionNum": "5.2",
"templateDTO": {
"sectionNum": 91,
"title": "ETHICAL CONDUCT OF THE STUDY",
"csrSectionNum": "5.2",
"parent": "5",
"sequence": 2,
"active": 1,
"subReportTypeId": 2,
"sectionType": "4",
"isHighlightSection": 0,
"children": [],
"contents": null
},
"isDefault": 1,
"parent": "5",
"sequence": 2,
"sectionType": "4",
"active": 1,
"studyId": 2,
"version": 0,
"userId": 0,
"createdDate": "2021-04-03 10:03:18",
"isHighlightSection": 0,
"sectionIdentifiedPercentage": "100",
"isBookmarked": false,
"children": [],
"contents": null,
"sfdtContent": null,
"keywordInput": false
},
{
"sectionNum": 9,
"title": "PATIENT INFORMATION AND CONSENT",
"csrSectionNum": "5.3",
"templateDTO": {
"sectionNum": 92,
"title": "PATIENT INFORMATION AND CONSENT",
"csrSectionNum": "5.3",
"parent": "5",
"sequence": 3,
"active": 1,
"subReportTypeId": 2,
"sectionType": "0",
"isHighlightSection": 0,
"children": [],
"contents": null
},
"isDefault": 1,
"parent": "5",
"sequence": 3,
"sectionType": "0",
"active": 1,
"studyId": 2,
"version": 0,
"userId": 0,
"createdDate": "2021-04-03 10:03:18",
"isHighlightSection": 0,
"sectionIdentifiedPercentage": "100",
"isBookmarked": false,
"children": [],
"contents": null,
"sfdtContent": null,
"keywordInput": false
}
],
"contents": null,
"sfdtContent": null,
"keywordInput": false
},
解决方案
如果你使用NestedTreeControl
你可以调用expandDescendants
这个控件上的函数来递归地扩展一个以给定数据节点为根的子树。
treeControl = new NestedTreeControl<any> (node => node.children);
dataSource = new ArrayDataSource(TREE_DATA);
ngOnInit() {
this.treeControl.dataNodes = TREE_DATA
this.treeControl.expandDescendants(TREE_DATA[1] /* for example */ )
}
推荐阅读
- java - talend (java) 将整数列乘以大小数列
- animation - Threejs FBX动画在更改对象材质后不起作用
- python-3.x - 无法计算数据框中具有特殊字符的行
- c# - 如何使用正则表达式从 C# 中的字符串中提取数字(整数或双精度数)和文本
- python - Python:通过使用每个其他字母“aceg”来更改像“abcdefg”这样的单词,然后按顺序添加其余的“bdf”。
- python - 设置多线程 Pyro 项目
- python - 在 Python 中自动收集数据到 POST
- macos - 如何在 SnailSVN 提交中包含新文件
- sql-server - 临时数据库的事务日志已满。如何不使用日志?
- java - 在使用 MVP 模型时更改 javaFX 中的场景