我正在拼命地尝试从JSON嵌套格式的角树中获取所选节点。到目前为止,我已经成功地获取了this.checklistSelection.selected
的平面节点的所选数组。但我需要的是,我需要以JSON格式获取所选节点,其中包含所有嵌套的JSON对象的级别。
[{item: "Risk Analysis", level: 0, expandable: true}
,{item: "Standard", level: 1, expandable: true}
,{item: "Active", level: 2, expandable: true}
,{item: "Volatility", level: 3, expandable: true}
,{item: "Contribution", level: 4, expandable: true}
,{item: "Total", level: 5, expandable: false}
,{item: "Systematic", level: 5, expandable: false}
,{item: "Specific", level: 5, expandable: false}
,{item: "VaR (95%, 2 weeks, Chebyshev)", level: 3, expandable: true}
,{item: "Contribution", level: 4, expandable: true}
,{item: "Total", level: 5, expandable: false}
,{item: "Systematic", level: 5, expandable: false}
,{item: "Specific", level: 5, expandable: false}
,{item: "Benchmark", level: 2, expandable: true}
,{item: "Volatility", level: 3, expandable: true}
,{item: "Contribution", level: 4, expandable: true}
,{item: "Total", level: 5, expandable: false}
,{item: "Systematic", level: 5, expandable: false}
,{item: "Specific", level: 5, expandable: false}
,{item: "VaR (95%, 2 weeks, Chebyshev)", level: 3, expandable: true}
,{item: "Contribution", level: 4, expandable: true}
,{item: "Total", level: 5, expandable: false}
,{item: "Systematic", level: 5, expandable: false}
,{item: "Specific", level: 5, expandable: false}
,{item: "Portfolio", level: 2, expandable: true}
,{item: "Volatility", level: 3, expandable: true}
,{item: "Contribution", level: 4, expandable: true}
,{item: "Total", level: 5, expandable: false}
,{item: "Systematic", level: 5, expandable: false}
,{item: "Specific", level: 5, expandable: false}
,{item: "VaR (95%, 2 weeks, Chebyshev)", level: 3, expandable: true}
,{item: "Contribution", level: 4, expandable: true}
,{item: "Total", level: 5, expandable: false}
,{item: "Systematic", level: 5, expandable: false}
,{item: "Specific", level: 5, expandable: false}]
预期值:
"Risk Analysis": {
"Standard": {
"Active": {
"Volatility": {
"Contribution": ["Total", "Systematic", "Specific"]
},
"VaR (95%, 2 weeks, Chebyshev)": {
"Contribution": ["Total", "Systematic", "Specific"]
}
},
"Portfolio": {
"Volatility": {
"Contribution": ["Total", "Systematic", "Specific"]
},
"VaR (95%, 2 weeks, Chebyshev)": {
"Contribution": ["Total", "Systematic", "Specific"]
}
},
"Benchmark": {
"Volatility": {
"Contribution": ["Total", "Systematic", "Specific"]
},
"VaR (95%, 2 weeks, Chebyshev)": {
"Contribution": ["Total", "Systematic", "Specific"]
}
}
}
}
}
有人能告诉我是否有Mat树提供的方法,或者任何一种函数可以做到这一点吗?
提前感谢:)
2条答案
按热度按时间bfhwhh0e1#
若要建立树状目录,您必须预先行程数据,为每个项目指派识别码。您可以使用堆栈来追踪指派时的相关性。
您可以分阶段完成此操作:
1.为每个项目指定
id
和parentId
键(applyRelationships
)1.将平面数组转换为树(
listToTree
)1.将树转换为对象(
treeToObject
)在原始示例中,我通过设置max-depth来强制嵌套每个对象。我没有使用
expandable
属性。在这个修改后的示例中,我丢弃了maxDepth
参数。第一个
原始响应
第一次
tvokkenx2#
Angular 材质树到JSON对象转换器。