javascript - 如何在本机反应中将对象从函数传递到组件
问题描述
我有一个使用“FlatList”创建的对象列表,当我单击一个元素时,我会通过“导航”转到一个页面并显示值。在 Ordine 组件中,我尝试打印,但它返回错误。
export default class ItemComponent extends Component {
//handling onPress action
getListViewItem = (item) => {
this.props.navigation.navigate('Ordine', { otherParam: 'Ordine' });
return (
<Ordine item={item} />
);
}
render() {
return (
<ScrollView showsVerticalScrollIndicator={false} contentContainerStyle={{
flexGrow:
1, centerContent: true, paddingBottom: Constants.statusBarHeight
}}>
<FlatList
data={this.props.items}
keyExtractor={(item, index) => index.toString()}
renderItem={({ item }) => <TouchableOpacity onPress={this.getListViewItem.bind(this,
item, this.props.navigation)} activeOpacity={1} >
<Item item={item} />
</TouchableOpacity>
}
ItemSeparatorComponent={this.renderSeparator}
/>
</ScrollView>
);
}
}
排序组件
export default class Ordine extends Component {
render() {
return (
<View
style={{
flexDirection: 'row',
height: 100,
padding: 20,
}}>
<Text>{this.props.item.Nome}</Text>
<Text>text</Text>
</View>
);
}
}
当我单击一个元素时,它返回错误:TypeError: undefined is not an object (evalating 'this.props.item.Nome')
解决方案
推荐阅读
- r - R - 具有动态列名且无聚合的透视数据框
- reactjs - 父组件重新渲染 useEffect
- mysql - 运行freeradius的mysql需要哪些主要设置?
- r - 在 shinyWidgets::airMonthinputPicker() 中选择当前月份
- swift - 无法将类型“[String : String]”的值转换为预期的参数类型“HTTPHeaders?”
- rabbitmq - RabbitMQ 同时发布和消费同一个队列
- python - Python/Sqlite3 - 从 for 循环列表中的项目中选择语句
- reactjs - 反应表并转到第一页/最后一页
- python - TypeError:元组索引必须是整数或切片,而不是列表-加载模型时 Keras
- mongodb - Mongodb在一段时间后关闭了连接异常:MongoSocketOpenException:异常打开套接字