This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const groupBy = (items, key) => { | |
let map = new Map(); | |
items.forEach(item => { | |
let val = item[key]; | |
if (map.get(val)) { | |
map.get(val).push(item) | |
} else { | |
map.set(val, []); | |
map.get(val).push(item) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 对象数组分类方法 | |
const groupBy = (items, key) => items.reduce( | |
(result, item) => ({ | |
...result, | |
[item[key]]: [ | |
...(result[item[key]] || []), | |
item, | |
], | |
}), | |
{}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const numArr = [ [1,2,3], [4,5,6] ]; | |
const initialValue = 0; | |
const totalNum = numArr.reduce( | |
(acc, curr) => acc + curr.reduce((acc_, curr_) => acc_ + curr_, 0), | |
initialValue | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<el-table | |
:data="tableData" | |
style="width: 100%" | |
:span-method="arraySpanMethod" | |
> | |
<el-table-column | |
prop="one" | |
label="一级分类" | |
width="180"> |