我无法在FlatList中显示在注释中检索到的数据。 有什么可能的解决方案,以便我可以显示UsersData中的所有数据并将其显示在我的render方法的FlatList中?
Firebase数据库
const comments = [
{reply: 'Reply 1'},
{reply: 'Reply 2'},
{reply: 'Reply 3'}];
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
comments: comments
}
}
componentDidMount() {
var that = this
firebase.database().ref('/UsersData').on('child_added', function (data) {
var newData = [...that.state.comments]
newData.push(data)
that.setState({ comments: newData })
})
}
render() {
return (
<View style={styles.container}>
<FlatList
contentContainerStyle={styles.paragraph}
data={this.state.comments}//The Data is not passed properly
renderItem={({data}) => <Text>{data.val().name}</Text>}
//It should be pas displayed here
/>
</View>
);
}
}
consloe.log(newData)返回