0
我对建设有一个简单的应用程序工作的反应,火力地堡 - 一种方法来管理收入和支出,和我的火力地堡设置结构如下:如何使用React访问Firebase中的嵌套数据?
"cashbook" : {
"expenditure" : {
"expenditure-1" : {
"amount" : "500",
"category" : "insurance",
"date" : "date",
"name" : "Life Insurance",
"type" : "recurring"
}
},
"income" : {
"salary" : {
"amount" : "500",
"category" : "salary",
"date" : "date",
"type" : "recurring"
}
}
}
我已经反应成立,并与工作完美只是支出,使用Re-base:
componentDidMount: function() {
// Two way data binding
base.syncState('cashbook/expenditure', {
context: this,
state: 'expenditure'
});
},
然后我就可以参考使用:this.state.expenditure
然而,当我尝试展开应用访问数据的收入,T h变成梨形。我修改了componentdidmount到:
componentDidMount: function() {
// Two way data binding
base.syncState('cashbook', {
context: this,
state: 'cashbook'
});
},
,并尝试以this.state.cashbook.expenditure
和this.state.cashbook.income
访问,但没有喜悦,我得到的错误:Uncaught TypeError: Cannot read property 'expenditure' of undefined
。
不太确定要尝试什么,任何指针都是神圣的棕色。
感谢提前:)
当你尝试访问这些东西时会发生什么?你是否收到特定的错误信息?如果您使用React开发人员工具查看组件的状态,您会看到什么? –
道歉。更新的主帖,但错误是'未捕获TypeError:无法读取属性'开支'未定义' – zeKoko
重新创建基地在这里。这听起来像是因为你的代码看起来很好,所以它可能是重新编译的问题。你介意在项目上创建一个问题,我会看看它吗? –