2016-12-12 47 views
2

我試圖調用onPaymentMethodReceived:function (obj)方法中的函數,但是我得到一個錯誤,obj包含付款現時。Braintree的onPaymentMethodReceived(obj)方法中的調用函數

我的js代碼是

this.braintree.setup(this.clientToken, "dropin", { 
      container: "dropin-container", 
      onPaymentMethodReceived:function (obj) { 
       console.log("nonce "+obj.nonce); 
       this.ckeckoutClick(obj.nonce) //I want call this function which is post request to server// 
      } 
     }) 

我的HTML是

<form id="checkout"> 
    <div id="dropin-container"></div> 
    <input type="submit" value="Place Order"> 
</form> 

請告訴我,我做錯了

謝謝

回答

2

如果你想使用this內該功能使用() =>而不是function()

this.braintree.setup(this.clientToken, "dropin", { 
     container: "dropin-container", 
     onPaymentMethodReceived: (obj) => { 
      console.log("nonce "+obj.nonce); 
      this.ckeckoutClick(obj.nonce) //I want call this function which is post request to server// 
     } 
    }) 

否則this.checkoutClick()將調用checkoutClickbraintree或從任何地方調用回調。

+1

非常感謝您的回答,它可以幫助我很多我投入更多的時間來弄清楚謝謝你讓我的一天:) – Malhari