React native 如何传递json数组值;是否转到另一个没有导航的页面?
我是新来的母语,我的英语很差,我找不到解决问题的办法。我的目标是,在获取json数组后,为组件提供onPress navigator函数,以便通过单击所选项,它可以将我发送回第二个页面,其中包含数组值的数据React native 如何传递json数组值;是否转到另一个没有导航的页面?,react-native,React Native,我是新来的母语,我的英语很差,我找不到解决问题的办法。我的目标是,在获取json数组后,为组件提供onPress navigator函数,以便通过单击所选项,它可以将我发送回第二个页面,其中包含数组值的数据 export default class Brewery extends React.Component{ state ={ breweries: [] } async componentDidMount(){ let url='https://jsonplacehold
export default class Brewery extends React.Component{
state ={
breweries: []
}
async componentDidMount(){
let url='https://jsonplaceholder.typicode.com/photos'
fetch(url)
.then((response) => response.json())
.then((json) =>{
console.log('JSON' , json)
this.setState({breweries: json})
})
.catch((error) => {
console.error(error);
this.setState({breweries:[]})
});
}
render(){
return(
<FlatList
numColumns={2}
data={this.state.breweries}
renderItem={({ item }) => (
<View style={styleSingleResult.box}>
<Image style={styleSingleResult.logo}
source={{uri: item.thumbnailUrl}} />
<Text>{item.title}</Text>
</View>
)}
ListEmptyComponent={() =>
<View>
<Text>NSE Ciae DIOLADRO</Text>
</View>}
/>
)
}
导出默认类Brewery扩展React.Component{
陈述={
啤酒厂:[]
}
异步组件didmount(){
让url为空https://jsonplaceholder.typicode.com/photos'
获取(url)
.then((response)=>response.json())
.然后((json)=>{
log('JSON',JSON)
this.setState({breweries:json})
})
.catch((错误)=>{
控制台错误(error);
this.setState({breweries:[]})
});
}
render(){
返回(
(
{item.title}
)}
ListMPtyComponent={()=>
迪奥拉多酒店
}
/>
)
}
}
我想我会用
<TouchableOpacity onPress={() => navigation.navigate('NextPage', item)}>
navigation.navigate('NextPage',item)}>
在目标页面中,获取:
<Text>{navigation.getParam('title')}</Text>
{navigation.getParam('title')}
回忆项目的价值。除了在Brewery类中,我不能实现“导航”方法。。如何解决?我了解了您的需求,因此解决方案是创建一个组件名称,例如:
<SecondScreen data={breweries} />
当安装组件时,若存在数据或从服务器中很好地获取数据,则可以访问数据,而不会出现任何错误
我希望能帮助你解释我的错误