在React Native中,路由传递数组时,需要将数组转换为字符串进行传递。然后在接收页面,再将字符串转换为数组。

例如,假设要传递一个名为data的数组,可以使用JSON.stringify()方法将数组转换为字符串进行传递:

this.props.navigation.navigate('NextScreen', { data: JSON.stringify(data) });

然后在接收页面,使用JSON.parse()方法将字符串转换为数组:

const { data } = this.props.route.params;
const dataArray = JSON.parse(data);

这样就可以正确地传递和接收数组数据了。


原文地址: https://www.cveoy.top/t/topic/iejC 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录