{
a: { a: 1 },
b: { b: 2 },
c: { c: 3 },
d: { d: 4 }
}
利用for in遍历对象对象
for (const key in obj) {
console.log(obj[key])
}
/*
a: { a: 1 },
b: { b: 2 },
c: { c: 3 },
d: { d: 4 }
*/
数据处理,构建对象体
const columns = []
for (const i in list) {
const data = {
text: list[i].name,
id: list[i].id,
children: [
]
}
if (list[i].city) {
for (const j in list[i].city) {
const city = {
text: list[i].city[j].name,
id: list[i].city[j].id,
children: [
]
}
data.children.push(city)
if (list[i].city[j].region) {
for (const x in list[i].city[j].region) {
const region = {
text: list[i].city[j].region[x].name,
id: list[i].city[j].region[x].id
}
city.children.push(region)
}
}
}
}
columns.push(data)
}

被折叠的 条评论
为什么被折叠?



