我试图在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);
}
我收到错误ERROR TypeError:无法读取属性' onPaymentStatus'为null
答案 0 :(得分:5)
你需要引用jQuery函数之外的组件,因为const component = this;
的含义在其中发生了变化
component.onPaymentStatus()
然后致电
#include <iostream>
using namespace std;
int main(){
long long int m, k;
cin >> m >> k;
while (cin.fail() || m < 0 || k < 0){
cin.clear();
cout << "please enter another input";
cin >> m >> k;
}
return 0;
}