【发布时间】:2018-09-23 01:15:53
【问题描述】:
我有一个连接到 firebase 的 react 原生 android 应用。其中一个表“内容”具有以下架构: firebase schema
我有一个“张贴!”按钮,按下时我希望将用户的帖子写入此 Firebase 表。
<Button
style={{height: 50, width: 20, paddingBottom: 10, paddingRight: 10}}
title="Post It!"
color='blue'
onPress={this.uploadTextPost}
/>
“uploadTextPost”函数如下所示:
uploadTextPost() {
this.rootRef('Content/qwa4').set({
Author: this.state.author,
Content_Text: this.state.textPostContent,
Content_Title: this.state.title,
Content_Type: 'TEXT',
Downvotes: this.state.downvotes,
Plot_Point: this.state.textPlotPoint,
Timestamp: this.state.timestamp,
Upvotes: this.state.upvotes
});
}
访问this.state:
this.rootRef = firebase.database().ref();
this.state = {
author: 'John JJ James',
textBookSubject: 'na',
textPlotPoint: 'na',
textPostContent: 'na',
upvotes: 0,
downvotes: 0,
title: 'Hopefully this works',
timestamp: '08/18/2018 19:59:23',
index: 0,
routes: [
{ key: 'first', title: 'Text Post' },
{ key: 'second', title: 'Art Post' },
{ key: 'third', title: 'Request'},
],
};
}
但是,当我在我的 Android 模拟器中按“发布”按钮对其进行测试时,nothing 会填充数据库。知道为什么吗?
【问题讨论】:
-
两件事:(1)您能发布更多代码,以便我们可以确保 this.rootRef 符合您的预期吗? (2) 确保在远程调试器中请求没有任何问题
-
@JasonKao 我在构造函数中添加了“rootRef”变量。控制台中没有错误消息。有什么想法吗?
-
刚刚发布了一个修复建议。
标签: javascript android firebase react-native mobile