1 回答
TA贡献1804条经验 获得超7个赞
function adds(datas){
var arr=[]
Object.keys(datas).map(r=>{
if(typeof datas[r] == 'object'){
arr.push({title:r,children:adds(datas[r])})
}else{
arr.push({title:r,dataIndex:r,key:r})
}
})
return arr
}
console.log(adds(schemasMessage[0]))
判断
"contacts": [
{
"name": "xx",
"position": "xx"
},
{
"name": "xx",
"position": "xx"
}
],
function adds(datas){
var arr=[]
Object.keys(datas).map(r=>{
if(!Array.isArray(datas[r])){
if(typeof datas[r] == 'object'){
arr.push({title:r,children:adds(datas[r])})
}else{
arr.push({title:r,dataIndex:r,key:r})
}
}else{
console.log(datas[r])
let arrs={'title':r,'children':[]}
arrs.children =datas[r].map((rs,index)=>{
if(typeof rs== 'object'){
return {title:r+index,children:adds(rs)}
}else{
return {title:rs,dataIndex:rs,key:rs}
}
})
arr.push(arrs)
}
})
return arr
}
console.log(adds(schemasMessage[0]))
添加回答
举报