简体   繁体   English

将特定的Firebase数据库值插入表React Redux

[英]Insert specific Firebase database values to table React Redux

I have firebase database that looks like this: firebase database 我有如下所示的firebase数据库: firebase数据库

I want to insert specific values from that database (adress, city, owner) into table that looks like this: table 我想从该数据库(地址,城市,所有者)中插入特定值到表中,如下所示: table

fething data from firebase looks like this: 从firebase收集的数据如下所示:

export function FetchData() {
  return dispatch => {
    firebase_db.on('value', snapshot => {
      dispatch({
        type: FETCH_DATA, 
        payload: snapshot.val()
      });
    });
  }
}

and I'm fetching it with componentDidMount(): 我用componentDidMount()获取它:

componentDidMount(){
    this.props.FetchData()
}

Then when I console.log this.props.data result is: console.log 然后,当我console.log时,this.props.data结果是: console.log

I'm mapping over list with function renderData(): 我正在使用功能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...). 这就是为什么表中有两行带有删除按钮的原因(不要介意该按钮,我稍后将其移到末尾...)。

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" 当我尝试this.props.data.adress时,它说的只是undefined ,可能是因为它是在props中有一些数据之前呈现的。。。此外,当我在控制台中将单个键作为全局变量并尝试temp1时。地址,我被通缉,正确值:“ Adress2”

How to put all those adress value from the database to adress column in the table? 如何将所有这些地址值从数据库放入表中的地址列? Maybe to use some middleware(reduxPromise or reduxThunk)? 也许要使用一些中间件(reduxPromise或reduxThunk)?

Thank you for your help!! 谢谢您的帮助!!

When you say: 当你说:

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.address时,它说只是未定义的,可能是因为它是在props中有一些数据之前呈现的。。。此外,当我在控制台中将单个键作为全局变量并尝试temp1时。地址,我被通缉,正确值:“ Adress2”

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是具有-LJNHbYR ... XtZr (基本上是哈希)之类的键的对象,因此您可以访问地址所有者必须像访问

this.props.data[< hash_value >].address
this.props.data[< hash_value >].owner

And since you are using < DataRow /> inside a map loop it would be great if you'd show us how is implemented this component 并且由于您在地图循环内使用<Da​​taRow />,所以如果您向我们展示如何实现此组件,那就太好了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM