将特定的Firebase数据库值插入表React Redux [英] Insert specific Firebase database values to table React Redux
问题描述
我有如下所示的firebase数据库: firebase数据库
I have firebase database that looks like this: firebase database
我想从该数据库(地址,城市,所有者)中将特定值插入如下所示的表中: 表
I want to insert specific values from that database (adress, city, owner) into table that looks like this: table
firebase的食物数据如下:
fething data from firebase looks like this:
export function FetchData() {
return dispatch => {
firebase_db.on('value', snapshot => {
dispatch({
type: FETCH_DATA,
payload: snapshot.val()
});
});
}
}
我正在使用componentDidMount()来获取它:
and I'm fetching it with componentDidMount():
componentDidMount(){
this.props.FetchData()
}
然后当我console.log this.props.data结果时,是: console.log
Then when I console.log this.props.data result is: console.log
我正在使用功能renderData()在列表上进行映射:
I'm mapping over list with function renderData():
renderData(dataList) {
return _.map(this.props.data, (post, key) => {
return <DataRow key={key} post={post} id={key} />
})
}
这就是为什么表中有两行带有删除按钮的原因(不要介意该按钮,我稍后将其移到末尾...).
and that is reason why are there two lines with delete button in the table(don't mind about that button, I will move it to the end later...).
那我如何获得对特定财产(例如地址或所有者)的访问权限?
当我尝试this.props.data.adress时,它说的只是undefined
,可能是因为它是在道具中有一些数据之前呈现的...此外,当我在控制台中将单键用作全局变量然后尝试temp1.adress,我想知道它的正确值:"Adress2"
So how can I get access to specific property(like adress or owner)?
When I try this.props.data.adress it says just undefined
, probably because it is rendered before there is some data in the props... Also, when I make single key as a global variable in the console and then try temp1.adress, I get wanted, correct value: "Adress2"
如何将所有数据库中的地址值放入表中的地址列? 也许要使用一些中间件(reduxPromise或reduxThunk)?
How to put all those adress value from the database to adress column in the table? Maybe to use some middleware(reduxPromise or reduxThunk)?
谢谢您的帮助!
推荐答案
当您说:
那么我如何获得对特定财产(如地址或所有者)的访问权? 当我尝试this.props.data.address时,它说只是未定义的,可能 因为它是在道具中没有数据之前渲染的. 当我在控制台中将单键作为全局变量,然后 尝试temp1.adress,我被想要了,正确的值:"Adress2"
So how can I get access to specific property(like address or owner)? When I try this.props.data.address it says just undefined, probably because it is rendered before there is some data in the props... Also, when I make single key as a global variable in the console and then try temp1.adress, I get wanted, correct value: "Adress2"
根据您在图像上显示的日志,我非常确定这是因为您的this.props.data
是具有 -LJNHbYR ... XtZr 之类的键的对象(基本上是哈希),因此访问地址或所有者,您将必须像
based on the log you showed on the image, I am quite sure that is because your this.props.data
is an object with keys like -LJNHbYR...XtZr (a hash basically) so to access the address or the owner you would have to access it like
this.props.data[< hash_value >].address
this.props.data[< hash_value >].owner
并且由于您使用的是<在 map 循环内的DataRow/> ,如果您向我们展示如何实现此组件,那就太好了
And since you are using < DataRow /> inside a map loop it would be great if you'd show us how is implemented this component
这篇关于将特定的Firebase数据库值插入表React Redux的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!