const groupBy = (array, f) => {
const groups = {}
array.forEach(function (o) {
const group = JSON.stringify(f(o))
groups[group] = groups[group] || []
groups[group].push(o)
})
return Object.keys(groups).map(function (group) {
return groups[group]
})
}
const arrayGroupBy = (list, groupId) => {
const sorted = groupBy(list, function (item) {
return [item[groupId]]
})
return sorted
}
const gridData =[
{
id: '22',
name: '张三',
code: '15'
},
{
id: '23',
name: '李四',
code: '15'
},
{
id: '24',
name: '李五',
code: '14'
}
]
const mergeList = arrayGroupBy(gridData, 'code')
console.log(mergeList)
console