I am desperately trying to get the selected nodes from angular tree in JSON nested format. So far I managed to get the selected array of flat nodes with this.checklistSelection.selected. But what I need, I need to get the selected nodes in JSON format, with all nested JSON objects by their level.
[{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}]
Expected:
"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"]
}
}
}
}
}
Can someone point me out if there a method that Mat tree offers, or any kind of function that could do this magic?
Thanks in advance :)