您的位置:首页 > 产品设计 > UI/UE

Each child in an array or iterator should have a unique "key" prop. Check the render method of `Tabl

2017-09-09 00:00 483 查看
Each child in an array or iterator should have a unique "key" prop. Check the render method of `Table Cell`

在使用ant的过程中,我相信有很多人都会遇到这个错误,

解决方式需要根据不再的场景来,遵循的只有一个原则,设置key值,

在table中:需要设置rowKey,如果dataSource中没有id的话,需要设置rowKey的值指向唯一.

在option中也 需要设置key值的,比如:有一段数据

const menuItem = [
{
value:'0',
text:'项目出勤'
},
{
value:'1',
text:'春节放假'
},
{
value:'2',
text:'春节待命'
},
{
value:'3',
text:'带薪假(婚/丧/探/亲)'
},
{
value:'4',
text:'带薪病假'
},
{
value:'5',
text:'事假'
},
{
value:'6',
text:'旷工'
},
];

在做循环的时候,需要设置key值,不然会报错,可以这样做,

<Select style={{ width: 80 }} onChange={this.fatherSelectChange.bind(this)}>
{menuItem.map((item,index) =>{
return(
<Option key={index} value={item.value}>{item.text}</Option>
)
})}
</Select>

欢迎各界大神前来指导,有问题也可以在下方留言交流.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  antd React
相关文章推荐