react Warning: Each child in an array or iterator should have a unique "key" prop. Check the render

来源:互联网 发布:javascript identifier 编辑:程序博客网 时间:2024/05/16 17:10

出现错误情况:Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `SubParent`. See https://fb.me/react-warning-keys for more information.

说明在遍历数组的时候,没有指定key,解决方法:

加上key属性,并赋值,如    

<tr key={tweet.id}>

render:function(){    var listItems = this.state.tweets.map(function(tweet, index) {        return (                <tr key={tweet.id}>                    <td>{tweet.id}{index}</td>                    <td>{tweet.pname}</td>                    <td>{tweet.name}</td>                    <td><a  href="#" >修改</a></td>                </tr>        );    });
}

0 0
原创粉丝点击