title: [
{
id: 1,
name: '财会经济',
children: [
{id: 11, name: '初级会计'},
{id: 12, name: '初级会计'}
]
},
{
id: 2,
name: '建筑工程',
children: [
{id: 21, name: '一级建造师'},
{id: 22, name: '二级建造师'}
]
},
{
id: 3,
name: '卫生资格',
children: [
{id: 23, name: '内科'},
{id: 24, name: '五官科'}
]
},
]
demo() {
this.title = this.getFlatArr(this.title)
console.log(this.title);
},
// 处理数据 将二维数组对象转为一维数组对象
getFlatArr(major, i) {
return major.reduce((array, item) => {
if (i == 2) {
item.name = '一 ' + item.name;
}
let flatArr = [...array, item];
if (item.children) {
flatArr = [...flatArr, ...this.getFlatArr(item.children, 2)];
}
return flatArr;
}, []);
},
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)