Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.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 如何在EventHandler函数内调用函数react native_Javascript - Fatal编程技术网

Javascript 如何在EventHandler函数内调用函数react native

Javascript 如何在EventHandler函数内调用函数react native,javascript,Javascript,我在我的项目中实现了这个库。我成功地得到了Paytm在我的 onPayTmResponse但现在我想将此响应发送到服务器,但在该函数中,我无法调用任何函数或声明它给我一个未定义的错误 componentWillMount() { if(Platform.OS == 'ios'){ const { RNPayTm } = NativeModules const emitter = new NativeEventEmitter(RNPa

我在我的项目中实现了这个库。我成功地得到了Paytm在我的 onPayTmResponse但现在我想将此响应发送到服务器,但在该函数中,我无法调用任何函数或声明它给我一个未定义的错误

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();
}