firebase - 如何在 FlatList(React Native)中从 Firebase 实时检索数据?
问题描述
我无法显示在 FlatList 的评论中检索到的数据。什么是可能的解决方案,以便我可以显示来自 UsersData 的所有数据并将其显示在我的渲染方法的 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) 返回
解决方案
推荐阅读
- azure-data-factory - 如何在数据流中加入数据
- ssh - 设置从 Linux 到 Windows 10 的无密码 SSH
- java - 如何处理 xml 标签中的下划线
- node.js - 使用 node.js 在 aws lambda 上调整图像大小的sharp或gm的更好替代品
- kubernetes - 是否将 liveness 或 readiness 探针的配置设置为“pod check”容器?
- node.js - OpenShift - 无法从 KafkaJS 连接 Strimzi
- jenkins - groovy.lang.MissingPropertyException:没有这样的属性:Jenkins for class:hudson
- android - Glide 4.10.0 : java.lang.IllegalStateException: GeneratedAppGlideModuleImpl 实现不正确
- autodesk-forge - Forge model.sync webhook 的安全/范围规则是否与其他规则不同?
- javascript - 嘲笑一个模块