Javascript ReactJS键不显示

Javascript ReactJS键不显示,javascript,reactjs,Javascript,Reactjs,试图使用ReactJS生成一个表,在这个表中,我希望有一个唯一的键来标识每一行(如ReactJS所建议的)。以下代码运行并生成我想要的表,但出现以下错误: Warning: 'Each child in an array or iterator should have a unique "key" prop' 查看我生成的HTML,“key”字段确实不存在。我也尝试过key={index},但它也不起作用 export class Tablecontent extends Component

试图使用ReactJS生成一个表,在这个表中,我希望有一个唯一的键来标识每一行(如ReactJS所建议的)。以下代码运行并生成我想要的表,但出现以下错误:

Warning: 'Each child in an array or iterator should have a unique "key" prop' 
查看我生成的HTML,“key”字段确实不存在。我也尝试过key={index},但它也不起作用

export class Tablecontent extends Component{

  constructor(props){
    super(props);
    this.state={
      fileinfo:'null'
    }
  }
  render(){
    //const fileinfo = this.props.rows;
    const fileinfo = ['myFile1.doc','myFile2.doc'];
    var row='';
    console.log("FILEINFO:"+fileinfo);
    if(fileinfo=='null')
    {
       row ='';
    }
    else {

     row = fileinfo.map((data,index) =>
    <tr>
      <td key="filename_{index}">{data}</td>
      <td key="date_{index}">2/12/2017</td>
      <td key="size_{index}">2.1 MB</td>
    </tr>
    );
  }
    return(
      <div>
        <table>
        <tbody>
          <tr>
            <th>Name</th>
            <th>Date Created</th>
            <th>Size</th>
          </tr>{row}</tbody>
    </table>
      </div>
    );

  }
}
导出类Tablecontent扩展组件{
建造师(道具){
超级(道具);
这个州={
fileinfo:'null'
}
}
render(){
//const fileinfo=this.props.rows;
constfileinfo=['myFile1.doc','myFile2.doc'];
var行=“”;
log(“FILEINFO:+FILEINFO”);
如果(fileinfo='null')
{
行=“”;
}
否则{
行=fileinfo.map((数据、索引)=>
{data}
2/12/2017
2.1MB
);
}
返回(
名称
创建日期
大小
{row}
);
}
}
生成的HTML:

<table>
    <tbody>
    <tr><th>Name</th><th>Date Created</th><th>Size</th></tr>
     <tr><td>myFile1.doc</td><td>2/12/2017</td><td>2.1 MB</td></tr>
    <tr><td>myFile2.doc</td><td>2/12/2017</td><td>2.1 MB</td>
    </tr>
    </tbody>
</table>

NameDate CreatedSize
myFile1.doc2/12/20172.1 MB
myFile2.doc2/12/20172.1 MB

它希望看到map函数中返回的外部元素上的键,如下所示。该键用于React的内部使用,不会显示在html中

 row = fileinfo.map((data,index) =>
    <tr key={index}>
      <td key="filename_{index}">{data}</td>
      <td key="date_{index}">2/12/2017</td>
      <td key="size_{index}">2.1 MB</td>
    </tr>
    );
row=fileinfo.map((数据、索引)=>
{data}
2/12/2017
2.1MB
);

可能是这样。我的服务器刚刚停机,所以我必须先将其恢复,然后才能以肯定的肯定回答!谢谢键应该在迭代的根元素中