根据字段进行数组分组
// list数组分组 根据名字 const groupYear = this.groupBy(list, (item) => { return item.year// 按照year进行分组 })
groupBy(list, fn) { const groups = {} list.forEach(function(o) { const group = fn(o) groups[group] = groups[group] || [] groups[group].push(o) }) const resData = [] Object.keys(groups).forEach((key) => { resData.push({ departName: key, children: groups[key] }) }) return resData },
分组后的数据格式