fetch('https://examplebutnotreallink.com/getyards')
.then(res=> res.json())
.then(res=>{
this.setState({
yards:res
}, ()=>{
let result = this.state.yards.map( yard=> {
return <TouchableOpacity onPress={this.toNav}><View style={{alignItems:'center'}}><Text style={{color:'black', textAlign:'center'}}><Text style={{color:'darkslateblue', fontSize:18}}>{yard.name}</Text>{"\n"}{yard.coordinates}</Text><Image source={{uri:yard.photourl}} style={{width:150,height:150}} /></View></TouchableOpacity>
});
console.log('these are the yards');
console.log(this.state.yards);
this.setState({
yardsRendered:result
})
})
})
基本上,我希望能够单击这些可触摸的院子对象项目中的每一个,以链接到其各自的院子页面。我可以在项目中使用任何唯一数据,例如密钥ID名称或其他名称。如何使用onPress函数执行此操作?
(最好是我希望能够将yard对象的属性传递给onPress函数)
谢谢