从Firebase推送通知中提取数据时发生错误

时间:2018-11-19 09:44:19

标签: javascript reactjs firebase react-native firebase-realtime-database

我是本机反应新手,并且正在研究Firebase推送通知。我收到通知,但问题是我无法获取数据并将其显示在平面列表中。通知显示完美。但是问题是为什么我无法获取数据。我希望在已添加到图片下方的通知列表中添加此事件数据。

componentWillMount() {
    const firebase = require("firebase");
    if (!firebase.apps.length) {
        firebase.initializeApp(db);
    }
    this.fetchEventsList()
}
// Fetch events list
fetchEventsList = () => {
    Preference.set('userPhoneCheck', '+917508060520');
    let phone = Preference.get('userPhoneCheck');

    firebase.database().ref('/users').child(phone).child('/events').once('value').then((snapshot) => {
        let data = snapshot.val();
        let items = Object.values(data);
        this.setState({
            userEventsList: items
        });
        // this.deleteOldEvents();
        this.initAllEventList();
    }).then((data) => {}).catch((error) => {
        //error callback
        console.log('error ', error)
    })
}


//fetch the friends list according to group name
initAllEventList = () => {
    //let groupName='G1';
    let eventId = '';
    let userEventsList = [...this.state.userEventsList];
    for (var i = 0; i < userEventsList.length; i++) {
        eventId = userEventsList[i].eventId;
        ToastAndroid.show("eventId>" + eventId, ToastAndroid.SHORT);
        if (eventId != '') {
            this.fetchFriendsList(eventId);
        }
    }
}
//app users remove that not in contacts
fetchFriendsList = (eventId) => {
    let allEventsList = [...this.state.allEventsList];
    firebase.database().ref('/events').child(eventId).once('value').then((snapshot) => {
        let data = snapshot.val();
        let items = Object.values(data);

        allEventsList.push(items);
        this.setState({
            allEventsList: allEventsList
        });

        ToastAndroid.show("kk>" + allEventsList.length, ToastAndroid.SHORT);

    }).then((data) => {

    }).catch((error) => {
        //error callback
        console.log('error ', error)
    })
}

enter image description here

0 个答案:

没有答案