如何将信息打印到从 firebase 获取的屏幕上?

How can I print the information to the screen fetched from firebase?

我正在努力控制控制台记录从 firebase 获取的信息。

我的代码: class HistoryPage 扩展组件 {

componentWillMount() {
    this.props.historyFetch();
}

render() {
    var ob = this.props.xyConsts[0];
    console.log(ob);
    return (
        <Text>{this.props.xyConsts[0].const1}</Text>
    );
}
}

const mapstateToProp = (state) => {
const xyConsts = _.map(state.historyPage, (val, uid) => {
    return { ...val, uid };
});
return { xyConsts };
};

export default connect(mapstateToProp, { historyFetch })(HistoryPage);

从控制台日志,我得到的信息可以在这里看到the console log printout

它看起来像一个物体。但是当我想打印出 "this.props.xyConsts[0].const1" 或其他键时,我得到了未定义。

我怀疑从 firebase 返回的信息不是一个对象,但我怎样才能到达并在屏幕上打印 "this.props.xyConsts[0].const1" 之类的东西?

我们将不胜感激。

主要有两种可能:

1) 尝试检查屏幕中的对象是否正确。

2) 如果对象是正确的,那么采用这样的对象引用:

var ob = this.props.xyConsts[0];
console.log(ob);
return (
    <Text>{ob.const1}</Text>
);

您可以通过两种不同的方式使用对象:

ob.const1 

ob['const1']

希望这对您有所帮助...