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

出现错误情况: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>

        );
    });
}

猜你喜欢

转载自blog.csdn.net/u010539006/article/details/62053004