let todoList = [
{
scopedSlotsTitle: 'orgNode',
title: '组织一',
id: '0752',
parentId: "0010",
children: [
{
scopedSlotsTitle: 'orgNode',
title: '子组织一',
id: '0001',
parentId: "0010",
children: [
{
scopedSlotsTitle: 'userNode',
title: '杜宇坤',
key: 'OPVhHrPM',
online: true,
children: []
}
]
},{
scopedSlotsTitle: 'orgNode',
title: '子组织二',
id: '0002',
parentId: "0010",
children: []
}
]
},{
scopedSlotsTitle: 'orgNode',
title: '组织二',
id: '0753',
parentId: "0010",
children: [
{
scopedSlotsTitle: 'userNode',
title: '杜宇坤',
key: 'OPVhHrPM',
online: true,
children: []
}
]
},{
scopedSlotsTitle: 'orgNode',
title: '组织三',
id: '0754',
parentId: "0010",
children: []
}
]
/**
* 格式化群组数据
* @param {Array} target 目标数组
* @param {Array} target 待处理数组
*/
function formatList (target, todoList) {
todoList.forEach(function (element) {
let newItem = {}
if (element.scopedSlotsTitle === 'orgNode') {
// 处理组织节点
newItem = {
key: element.id,
title: element.title,
parentId: element.parentId,
online: false,
scopedSlots: {
title: element.scopedSlotsTitle
},
children: formatList([], element.children)
}
} else if (element.scopedSlotsTitle === 'userNode') {
// 处理用户节点
newItem = {
key: element.key,
title: element.title,
parentId: '',
online: element.online,
scopedSlots: {
title: element.scopedSlotsTitle
},
children: []
}
}
target.push(newItem)
})
}
const testList = formatList([], todoList)
console.log(testList)
console