【发布时间】:2019-12-06 05:44:12
【问题描述】:
我正在从云存储中检索数据作为对象数组,并将对象的值作为道具传递给另一个组件:
renderTips() {
firebase.firestore().collection('pendingtips').get()
.then(doc => {
doc.forEach(tip => {
const tipData = tip.data();//array's object
console.log(tipData.tip); //prints tip as expected
console.log(tipData.name); //prints name as expected
return <PendingTip key={tipData.tip} name={tipData.name} tip={tipData.tip} />; //doesn't returning enything
});
})
.catch(() => Alert.alert('error'));
}
render() {
return (
<View style={styles.containerStyle}>
<ScrollView style={styles.tipsContainerStyle}>
{this.renderTips()}
</ScrollView>
</View>
);
}
对象数组如下所示:
{ name: 'Danny', tip: 'Be careful when crossing the road' },
{ name: 'Alex', tip: 'Drink water' }
期望在我的 ScrollView 中我会有一个“提示”列表。相反,我什么也得不到,就好像这些值没有被传递给组件一样。
提前致谢。
【问题讨论】:
标签: javascript arrays reactjs firebase react-native