Object.keys(obj)
参数:要返回其枚举自身属性的对象
返回值:一个表示给定对象的所有可枚举属性的字符串数组
在实际开发中,我们有时需要知道对象的所有属性;
ES5 引入了Object.keys方法,成员是参数对象自身的(不含继承的)所有可遍历( enumerable )属性的键名。
参考 :https://blog.csdn.net/wangxinxin1992816/article/details/124523086
<template>
<div></div>
</template>
<script>
export default {
data() {
return {
tableData: [{
id: '12987122',
name: '王小虎',
amount3: '10'
}, {
id: '12987123',
name: '王小虎',
amount3: '10'
}, {
id: '12987123',
name: '王小虎',
amount3: '10'
}, {
id: '12987124',
name: '王小虎',
amount3: '9'
}],
};
},
computed: {
map() {
const temp = {}
this.tableData.forEach(item => {
if (Object.keys(temp).includes(item.amount3)) {
temp[item.amount3].push(item)
} else {
temp[item.amount3] = [item]
}
})
return Object.keys(temp).map(key => {
return {
value: key,
length: temp[key].length
}
})
}
},
methods: {
objectSpanMethod({ row, column, rowIndex, columnIndex }) {
if (columnIndex === 2) {
console.log({ row, column, rowIndex, columnIndex })
this.map.forEach(item => {
if (row.amount3 === item.value) {
console.log({
rowspan: item.length,
colspan: 1
}, '1231612')
return {
rowspan: item.length,
colspan: 1
}
}
})
}
}
}
};
</script>