Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/427.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
Javascript 按下按钮时的反应本机按钮不';行不通_Javascript_Button_React Native_Onpress - Fatal编程技术网

Javascript 按下按钮时的反应本机按钮不';行不通

Javascript 按下按钮时的反应本机按钮不';行不通,javascript,button,react-native,onpress,Javascript,Button,React Native,Onpress,我无法将onPress方法绑定到JSX按钮。 我已经尝试了很多不同的解决方案,但没有一个有效 onPress方法: class ScreenEnterPlayerNames extends Component { constructor(props) { super(props); } static navigationOptions = { title: 'Player Names', }; onPressStartTheGame = () =>

我无法将onPress方法绑定到JSX按钮。 我已经尝试了很多不同的解决方案,但没有一个有效

onPress方法:

class ScreenEnterPlayerNames extends Component {

  constructor(props) {
    super(props);
  }

  static navigationOptions = {
    title: 'Player Names',
  };

  onPressStartTheGame = () => {
    console.log("Pushed button Start the Game!")
    //dispatch({ type: ADD_PLAYER_NAME, playerNumber: 5, playerName: "Sandro" })
  }
按钮:

return (
      <View style={styles.viewMain}>
        <View style={styles.viewTxt}>
          <Text style={styles.TxtHeading}>
            Please enter the names in sequence.
          </Text>
        </View>
        <ScrollView style={styles.viewTextBox}>
          {textBoxes}
        </ScrollView>

        <View style={styles.viewButton}>
          <Button
            title='Start the Game!'
            onPress={() => this.onPressStartTheGame}
          />
        </View>
      </View>
    );
  }
}
我尝试将函数更改为:

onPressStartTheGame()  {...
所以我很确定还有别的问题,但我不知道是什么


谢谢!:-)

试试你的方法

 onPressStartTheGame(){
    console.log("Pushed button Start the Game!")
    //dispatch({ type: ADD_PLAYER_NAME, playerNumber: 5, playerName: "Sandro" })
  }
就这样说吧

onPress={this.onPressStartTheGame.bind(this)}
在这里,您可以再次检查并尝试在沙箱中进行操作。

很好用,谢谢!仍然不确定为什么它不能与其他方法一起工作。谢谢
onPress={this.onPressStartTheGame.bind(this)}