试过Math.random()生产随机数,这个方案不太好,内存会爆掉,为什么?
getRandomIntInclusive = (min, max) => {
min = Math.ceil(min)
max = Math.floor(max)
return Math.floor(Math.random() * (max - min + 1)) + min
}
rowKey: record => this.getRandomIntInclusive(100000, 999999),
还有其他办法吗?
其实是用了antd的table组件rowKey属性传值的方式,有其他办法吗
没有稳定的标识符可选择的情况下
遍历数组时,如果数组内是对象的话,可以直接使用对象的某个惟一值的属性,比如
ID
。另外可以使用遍历的索引
index
.如:[].map((o, index) => <Component key={index}/>)
antd
的Table
组件中的rowKey
你完全可以使用dataSource
中的id
。如:rowKey={recode => recode.id}