js递归一个数组
当我开发项目的时候有时候遇到这样的数据结构 列如树形数据
递归这个数组
let labelData= function (datalist) {
console.log(datalist);
for (var i in datalist) {
var obj = datalist[i]
if (obj.children) {
if (obj.children.length === 1) {
obj.child = obj.children[0]
} else {
obj.child = obj.children
}
labelData(obj.children)
} else {
if (obj.path === this.$route.path) {
let paneData.push({
name: obj.name,
path: obj.path,
meta: {
id: obj.name,
title: obj.meta.title,
particulars: false
}
})
return obj
}
}
}
},