React.js create loop through Array

后端 未结 3 1339
没有蜡笔的小新
没有蜡笔的小新 2020-12-08 02:36

I\'m trying to display a Table of 10 Players. I get the data from via ajax and pass it as props to my Child.

var CurrentGame = React.createClass({

  // get          


        
3条回答
  •  没有蜡笔的小新
    2020-12-08 03:18

    In CurrentGame component you need to change initial state because you are trying use loop for participants but this property is undefined that's why you get error.,

    getInitialState: function(){
        return {
           data: {
              participants: [] 
           }
        };
    },
    

    also, as player in .map is Object you should get properties from it

    this.props.data.participants.map(function(player) {
       return 
  • {player.summonerName}
  • // -------------------^^^^^^^^^^^---------^^^^^^^^^^^^^^ })

    Example

提交回复
热议问题