Javascript 按下按钮时的反应本机按钮不';行不通
我无法将onPress方法绑定到JSX按钮。 我已经尝试了很多不同的解决方案,但没有一个有效 onPress方法: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 = () =>
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)}