从状态映射数组内的数组

Som*_*ame 0 javascript reactjs react-native map-function

所以我的代码是:

class MyComponent extends Component {
    constructor(props) {
      super(props);

        this.state = {

            myArray: [
                {id:1, continent:[
                    {id:1, name: 'Russia'},
                    {id:2, name: 'Germany'},
                    {id:3, name: 'Poland'}
                ]},

                {id:2, continent:[
                    {id:1, name: 'China'},
                    {id:2, name: 'India'},
                    {id:3, name: 'Bangladesh'}
                ]},

                {id:3, continent:[
                    {id:1, name: 'Brazil'},
                    {id:2, name: 'Peru'},
                    {id:3, name: 'Chile'}
                ]}      
            ],

            otherValue: 23
        }
    }


    subBoardList(id){
        return this.state.myArray[id].map((continent) => {
            return(
                <View>
                    <Text>{continent.name}</Text>
                </View>
            )
        })
    }


  render() {
    return (
      {this.subBoardList(2)}
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

我想显示将 id 传递给subBoardList函数的大洲数组的内容。我怎么做?

错误:

TypeError: undefined is not an object (evaluating 'this.state.myArray[id].map')
Run Code Online (Sandbox Code Playgroud)

T. *_*ort 5

你应该使用:

this.state.myArray[id].continent.map(...
Run Code Online (Sandbox Code Playgroud)