需求就是arr里有list所在的层级不确定所在父级字段也不确定,请问怎么把list里的项取出,放到另数组。
还有就是arr项里没有list的,取当前项
可以办到吗。想了半天没辙,谢谢各位
const arr = [
{
"id": 0,
"type": "input",
"name": "单行文本"
},
{
"type": "grid",
"name": "栅格布局",
"columns": [
{
"span": 8,
"list": [
{
"id": 1,
"type": "input",
"name": "测试编码"
}
]
},
{
"span": 8,
"list": [
{
"id": 2,
"type": "input",
"name": "测试名称"
}
]
},
{
"span": 8,
"list": [
{
"id": 3,
"type": "input",
"name": "单行文本"
}
]
}
]
},
{
"type": "card",
"name": "卡片布局",
"list": [
{
"type": "input",
"name": "单行文本"
},
{
"type": "input",
"name": "单行文本",
"icon": "icon-write"
}
]
},
{
"type": "table",
"name": "表格布局",
"trs": [
{
"tds": [
{
"colspan": 1,
"rowspan": 1,
"list": [
{
"type": "input",
"name": "单行文本"
}
]
}
]
}
]
},
{
"type": "tabs",
"name": "Tab页签",
"tabs": [
{
"key": "1",
"tab": "页签1",
"list": [
{
"type": "input",
"name": "单行文本"
}
]
},
{
"key": "2",
"tab": "页签2",
"list": [
{
"type": "input",
"name": "单行文本"
}
]
}
]
}
]
想要的结果
[
{
"id": 0,
"type": "input",
"name": "单行文本"
},
{
"id": 1,
"type": "input",
"name": "测试编码"
},
{
"id": 2,
"type": "input",
"name": "测试名称"
}
...
...
...
]