将 JavaScript 嵌套数组转换为启动树格式
convert JavaScript nested array for priming tree format
我有以下 JAVASCRIPT 对象,我需要将其转换为 primeng 树格式,请帮助
输入
{
"com": {
"ups": {
"demo": {
"a": 9
}
}
}
}
预期输出
[
{
"label": "COM",
"data": "COM",
"children": [{
"label": "ABC",
"data": "abc",
"children": [ "label": "x" data": "x" ,children:[]]
}]
}]
validate(a) {
let newArr = [];
for (const key in a) {
if (key) {
newArr.push({data: key, label: key, childern: this.validate(a[key])});
}
}
return newArr;
}
const a = {
"com": {
"ups": {
"demo": {
"a": 9
}
}
}
};
console.log(this.validate(a));
我有以下 JAVASCRIPT 对象,我需要将其转换为 primeng 树格式,请帮助
输入
{
"com": {
"ups": {
"demo": {
"a": 9
}
}
}
}
预期输出
[
{
"label": "COM",
"data": "COM",
"children": [{
"label": "ABC",
"data": "abc",
"children": [ "label": "x" data": "x" ,children:[]]
}]
}]
validate(a) {
let newArr = [];
for (const key in a) {
if (key) {
newArr.push({data: key, label: key, childern: this.validate(a[key])});
}
}
return newArr;
}
const a = {
"com": {
"ups": {
"demo": {
"a": 9
}
}
}
};
console.log(this.validate(a));