前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Each child in an array or iterator should have a unique "key" prop. Check the render method of `Tabl

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

作者头像
杭州前端工程师
发布2018-06-15 11:56:55
1.2K0
发布2018-06-15 11:56:55
举报
文章被收录于专栏:前端大白专栏

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值的,比如:有一段数据

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

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

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

欢迎各界大神前来指导,有问题也可以在下方留言交流.

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档