Uncaught TypeError:无法读取未定义的属性“ map”(REACT NATIVE-Javascript)

时间:2020-04-01 20:37:11

标签: javascript reactjs react-native react-native-android

曾经尝试导入Json文件,然后在React Native应用程序中浏览并显示它。我只是在学习React Native,并同时使用Javascript。

import React, { Component } from 'react';
import {
    Text,
    View,
    AsyncStorage
} from 'react-native';

import{eventos} from './Events';

export default class Admin extends React.Component{

    constructor(props){
        super(props);
        this.state={
            eventos
        }
        try{
            AsyncStorage.getItem(eventos).then((value)=>{
                if(value!=null){
                    console.log("Events esta completo")
                }else{
                    console.log("Events esta vacio")
                }
                this.setState({
                    eventos:JSON.parse(value)
                })
            })
        }catch(err){
            console.log(err)
        }
    }
parseEventsData(){

        console.log("Deberia salir algo")
        return this.state.events.map((eventos,i)=>{
            return(
                <View key={i}>
                    <Text>
                        {eventos.title}
                    </Text>
                    <Text>
                        {eventos.responsible}
                    </Text>
                    <Text>
                        {eventos.description}
                    </Text>
                </View>
            )
        })
}
render(){
    return(
        <View>
            {this.parseEventsData()}
            <Text>No salio nada</Text>                 
        </View>

    );
}

}

下一个是杰森。

enter image description here

这是我得到的错误。

enter image description here

我正在学习React Native,并同时使用Javascript。

enter image description here

1 个答案:

答案 0 :(得分:0)

检查代码,您会注意到状态var被称为“ eventos”,并且正在通过“ this.state.events”进行映射。只是一个错字。