【发布时间】:2019-11-08 03:24:37
【问题描述】:
我目前正在进行一个项目,想出了两组不同的代码,想知道两者之间是否存在差异。
ReactJS(最新版本)
1.
columns.map(v => v.aggregate = (values) => values[0]);
2.
columns = columns.map( v => ({
...v,
aggregate : (values) => values[0]
}))
预期结果:
const columns = [
{
Header: 'ID',
accessor: 'empid',
shown: true,
width: 130
}, {
Header: 'Name',
accessor: 'name',
shown: true,
aggregate: (values) => values[0],
width: 130
}, {
Header: 'Age',
accessor: 'age',
shown: true,
aggregate: (values) => values[0],
}, {
Header: 'Email',
accessor: 'email',
shown: true,
aggregate: (values) => values[0],
width: 150
}, {
Header: 'Birthday',
accessor: 'birthday',
shown: true,
aggregate: (values) => values[0],
width: 150
}
];
我将把它添加到 ReactTable 组件中,并通过 id 聚合透视。
【问题讨论】:
-
一个改变数组中的现有对象,另一个不改变
-
感谢@CertainPerformance 的回复!
标签: javascript arrays reactjs object ecmascript-6