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

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>
    )
  }
}

 

posted @ 2017-05-27 15:06  slardarr  阅读(339)  评论(0编辑  收藏  举报