Each child in an array or iterator should have a unique \"key\" prop.

南楼画角 提交于 2019-11-28 13:59:57

Each child in an array or iterator should have a unique "key" prop.

解决办法使用React.Children.toArray 

import React from 'react'
import Slider from 'react-slick'

export default class Table extends React.Component{
  constructor(props) {
    super(props)
    this.state = {
      th: [ "名称", "城市", "邮编" ]
    }
  }
  render() {
    const { table, children } = this.props
    return(
      <table className="table table-striped">
        <caption>条纹表格布局</caption>
        <thead>
          <tr>
            { React.Children.map( this.state.th , th => <th>{ th }</th> ) }
          </tr>
        </thead>
        <tbody>
        { React.Children.toArray( table.map(o=>(
          <tr>
            <td>{o.name}</td>
            <td>{o.city}</td>
            <td>{o.邮编}</td>
          </tr> 
        )) )}
        </tbody>
      </table>
    )
  }
}

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!