Javascript 如何在EventHandler函数内调用函数react native
我在我的项目中实现了这个库。我成功地得到了Paytm在我的 onPayTmResponse但现在我想将此响应发送到服务器,但在该函数中,我无法调用任何函数或声明它给我一个未定义的错误Javascript 如何在EventHandler函数内调用函数react native,javascript,Javascript,我在我的项目中实现了这个库。我成功地得到了Paytm在我的 onPayTmResponse但现在我想将此响应发送到服务器,但在该函数中,我无法调用任何函数或声明它给我一个未定义的错误 componentWillMount() { if(Platform.OS == 'ios'){ const { RNPayTm } = NativeModules const emitter = new NativeEventEmitter(RNPa
componentWillMount() {
if(Platform.OS == 'ios'){
const { RNPayTm } = NativeModules
const emitter = new NativeEventEmitter(RNPayTm)
emitter.addListener('PayTMResponse', this.onPayTmResponse)
}else{
DeviceEventEmitter.addListener('PayTMResponse', this.onPayTmResponse)
}
//this.makeRemoteRequest();
}
onPayTmResponse(response) {
// Process Response
// response.response in case of iOS
// reponse in case of Android
var actual = "";
if(Platform.OS == 'ios'){
actual = JSON.parse(response.response);
}else{
actual = JSON.parse(response);
}
console.log(actual, this.state);
if(actual.RESPCODE == "01"){
// Place Order
placeOrder();
}else{
alert(actual.RESPMSG);
this.setState({loading: false, buttonText: 'Continue'});
}
}
将onPayTmResponse函数与此内部组件绑定
现在,您应该能够在onPayTmResponse中调用setState。的可能重复项
componentWillMount() {
this.onPayTmResponse = this.onPayTmResponse.bind(this); // note: we bind onPayTmResponse with this
if(Platform.OS == 'ios'){
const { RNPayTm } = NativeModules
const emitter = new NativeEventEmitter(RNPayTm)
emitter.addListener('PayTMResponse', this.onPayTmResponse)
}else{
DeviceEventEmitter.addListener('PayTMResponse', this.onPayTmResponse)
}
//this.makeRemoteRequest();
}