React native 当我在react native中使用map时,如何防止此按钮运行?
我的代码:React native 当我在react native中使用map时,如何防止此按钮运行?,react-native,React Native,我的代码: {this.state.News.slice(0, this.state.currentShow).map((item) => { return ( <View> <View> <View> <Text>{item.Title}</Text> <Text>{item.Content}</Text>
{this.state.News.slice(0, this.state.currentShow).map((item) => {
return (
<View>
<View>
<View>
<Text>{item.Title}</Text>
<Text>{item.Content}</Text>
</View>
<View>
<Image source={{uri: item.Image}} />
</View>
</View>
<View>
<Text>{item.creationTime}</Text>
<Button onPress={this.gotoNews(item.Id.toString())}>
<Text>Load More</Text>
</Button>
</View>
</View>
)
})}
每当运行此页面时,一切正常,但为什么在加载react native屏幕时会运行onPress按钮 尝试将按钮处理程序调用从函数调用更改为函数调用 您可以使用ES6箭头功能执行此操作:
<Button onPress={()=>this.gotoNews(item.Id.toString())}>
<Text>Load More</Text>
</Button>