我正在尝试在jQuery函数内调用onPaymentStatus()函数。但是我无法使用“这个”范围
this.braintree.client.create({
authorization: 'client_token'},
(err, client) => {
client.request({
endpoint: 'payment_methods/credit_cards',
method: 'post',
data: data
}, function (requestErr, response) {
if (requestErr) { throw new Error(requestErr); }
console.log('Got nonce:', response.creditCards[0].nonce);
this.onPaymentStatus(response.creditCards[0].nonce); //
});
});
onPaymentStatus (nonce) {
console.log(nonce);
}
Run Code Online (Sandbox Code Playgroud)
我收到错误ERROR TypeError:无法读取null的属性'onPaymentStatus'
您需要引用jQuery函数外部的组件,作为其this内部更改的含义
const component = this;
Run Code Online (Sandbox Code Playgroud)
然后打电话
component.onPaymentStatus()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1607 次 |
| 最近记录: |