js处理数据?
let arr = [ [
{
"orgName": "123456",
"levelType": "0",
"orgCode": "2365506"
},
{
"orgName": "asdfasdf",
"levelType": "0",
"orgCode": "2380354"
},
{
"orgName": "testet",
"levelType": "0",
"orgCode": "5165161"
},
{
"orgName": "testet",
"levelType": "0",
"orgCode": "2380357"
},
{
"orgName": "asdfasdf",
"levelType": "0",
"orgCode": "2380358"
},
{
"orgName": "testetwet",
"levelType": "0",
"orgCode": "2380359"
},
{
"orgName": "testetet",
"levelType": "0",
"orgCode": "2380360"
},
{
"orgName": "阿斯顿",
"levelType": "0",
"orgCode": "2034440"
},
{
"orgName": "标签测试2",
"levelType": "0",
"orgCode": "2366126"
},
{
"orgName": "科勒厨卫有限公司javajava",
"levelType": "0",
"orgCode": "202029558"
}
]
]
将每一层添加children:[],并将orgName改名为label
回答:
arr[0] = arr[0].map(({orgName, ...v}) => ({...v, label: orgName, children: []}))console.log(arr)
回答:
let list = [] for (let item of arr) {
item = item.map(val => {
val.label = val.orgName
delete val.orgName
return { ...val, children: [] }
})
list.push(item)
}
回答:
JavaScript 数据处理 - 列表篇 - 边城客栈 - SegmentFault 思否
JavaScript 数据处理 - 映射表篇 - 边城客栈 - SegmentFault 思否
以上是 js处理数据? 的全部内容, 来源链接: utcz.com/p/933634.html