简体   繁体   English

警告:数组或迭代器中的每个子代均应具有唯一的“键”道具。 检查“ MovieResults”的渲染方法

[英]Warning: Each child in an array or iterator should have a unique “key” prop. Check the render method of `MovieResults`

I can not go to the Move.js page to page Details.js 我无法转到Move.js页面到页面Details.js

I do not understand why I have this response : Warning: Each child in an array or iterator should have a unique "key" prop. 我不明白为什么会有这个响应:警告:数组或迭代器中的每个子代都应具有唯一的“键”道具。 Check the render method of MovieResults 检查MovieResults的渲染方法

Movie.js : Movie.js:

var Movie = React.createClass({
    render: function(){
        var link = 'http://www.imdb.com/title/' + this.props.movie.imdbID;
        var myLink = 'search/' + this.props.movie.imdbID;

        return(
            <div className="well">
                <div className="row">
                    <h4 className="text-center">
                        <Link to={myLink} activeClassName="current">{this.props.movie.Title}</Link>
                    </h4>
                </div>


            </div>    
        )
    },
});

Details.js : Details.js:

var Details = React.createClass({
    render: function(){

        var link = 'http://www.imdb.com/title/' + this.props.movie.imdbID;

        var title = this.props.movie.Title;
        var year = this.props.movie.Year;
        var type = this.props.movie.Type;
        var poster = this.props.movie.Poster;
        var imdbID = this.props.movie.imdbID;

        return(
            <div className="well">
                <div className="row">
                    <div className="col-md-4">
                        <img className="thumbnail" src={poster} /> 
                    </div>
                    <div className="col-md-8">
                        <h4><a href={this.props.movie.Title}> {title}</a></h4>
                        <ul className="padding">
                            <li className="list-group-item">Type : {type}</li>
                            <li className="list-group-item">Year Released : {year}</li>
                            <li className="list-group-item">Id imdb : {imdbID}</li>
                        </ul>
                        <a className="btn btn-primary" href={link}>View on IMDB</a>
                    </div>
                </div>
                <Movie movie={this.props.Details} key={i} />
            </div>    
        )
    },
});

DOCS DOCS

The key should always be supplied directly to the components in the array, not to the container HTML child of each component in the array 键应始终直接提供给数组中的组件,而不是数组中每个组件的容器HTML子级。

So... Add key attribute to the first child <div> 所以...将key属性添加到第一个子<div>

var MovieResults = React.createClass({
  render: function(){
    return(
      <div>
        <h3 className="text-center"> Results </h3>
        {
          this.props.movies.map(function(movie, i){
            return(
              <div key={i}>
                <Movie movie={movie}/>
              </div>
            )
          })
        }
      </div>    
    )
  }
})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 警告:数组或迭代器中的每个孩子都应该有一个唯一的“键”道具。 检查 `ListView` 的渲染方法 - Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView` 警告:数组或迭代器中的每个子代均应具有唯一的“键”道具。 检查`单位`的渲染方法 - Warning: Each child in an array or iterator should have a unique “key” prop. Check the render method of `Units` 反应警告:数组或迭代器中的每个子元素都应该有一个唯一的“键”属性。 检查`App`的渲染方法 - React Warning: Each child in an array or iterator should have a unique “key” prop. Check the render method of `App` 警告:数组或迭代器中的每个子代均应具有唯一的“键”道具。 检查“搜索”的渲染方法 - Warning: Each child in an array or iterator should have a unique “key” prop. Check the render method of 'search' 数组或迭代器中的每个子代都应具有唯一的“键”道具。 检查`Abstractfactory`的渲染方法。 - Each child in an array or iterator should have a unique “key” prop. Check the render method of `Abstractfactory` 警告:数组或迭代器中的每个子节点都应该具有唯一的“键”支柱。 检查`SocialMenu`的render方法。 (Meteor.js应用程序中的React.js) - Warning: Each child in an array or iterator should have a unique “key” prop. Check the render method of `SocialMenu`. (React.js in a Meteor.js app) 警告:列表中的每个孩子都应该有一个唯一的“关键”道具。 检查`Notes`的渲染方法 - Warning: Each child in a list should have a unique "key" prop. Check the render method of `Notes` 警告:列表中的每个孩子都应该有一个唯一的“关键”道具。 检查 `RenderComments` 的渲染方法 - Warning: Each child in a list should have a unique "key" prop. Check the render method of `RenderComments` 警告:数组或迭代器中的每个子代都应具有唯一的“键”道具。 li中已添加的关键道具 - Warning: Each child in an array or iterator should have a unique “key” prop.; key prop already added in li 数组或迭代器中的每个子代都应具有唯一的“键”道具。 - Each child in an array or iterator should have a unique “key” prop.
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM