Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 当我在react native中使用map时,如何防止此按钮运行?_React Native - Fatal编程技术网

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>