在本机运行遇到此问题的情况下创建应用程序.基本上,我应该创建一个页面,以打印当前登录到数据库(firebase)的用户的数据.我设法创建了一种排行榜,可以在所有页面上用数据打印所有用户,但是我无法弄清楚哪里出了问题.有人能帮我吗?
https://snack.expo.io/@khal_d/proj-p-3
import React,{ Component } from 'react';
import { View,TouchableOpacity,StyleSheet,Button,Text,ScrollView,ListItem } from 'react-native';
import { Input,Card} from 'react-native-elements';
import * as firebase from 'firebase';
export default class User extends Component {
static navigationOptions = {
title: 'UserInfo',};
state = {
data: [],};
// Controllare qui
componentDidMount(){
//leggere array dal db
const currentUID = firebase.auth().currentUser.uid;
const path ="/users/" + currentUID;
const users = firebase.database().ref(path);
users.on("value",snap => {
console.log("log di snap" + snap);
//ciclo
var elenco = [];
snap.forEach(child => {
elenco.push({
name: child.val().name,surname: child.val().surname,email: child.val().email,image: child.val().image,})
});
console.log("altro log finale" + elenco);
this.setState({data:elenco})
});
}
// controllare fino a qua
render() {
return (
<ScrollView>
<View>
<Card> //fix evertything all'interno di card
{
this.state.data.map((l,i) => (
<ListItem
key={i}
leftAvatar={{ source: { uri: l.image } }}
title={l.name}
subtitle={l.surname}
/>
))
}
</Card>
</View>
</ScrollView>
);
}
}
最佳答案
原文链接:https://www.f2er.com/js/531145.html