Javascript Can';t从从承诺中获取的对象中检索值
我正在尝试使用Stripe的Javascript Can';t从从承诺中获取的对象中检索值,javascript,object,stripe-payments,Javascript,Object,Stripe Payments,我正在尝试使用Stripe的createSource,为此,我在客户机中使用了如下承诺: function prepare(name, email, phone){ stripe.createSource({ type: 'oxxo', amount: <?= $price ?>, currency: 'mxn',
createSource
,为此,我在客户机中使用了如下承诺:
function prepare(name, email, phone){
stripe.createSource({
type: 'oxxo',
amount: <?= $price ?>,
currency: 'mxn',
owner: {
name: name,
email: email,
phone: phone,
},
}).then(function(result) {
handle(result);
}).catch(function(err){
console.log("Error!");
console.error(err);
});
}
但是,执行此操作时,我得到:uncaughttypeerror:无法读取未定义的属性“number”
,尽管我可以在控制台中看到该值:
我在这里遗漏了什么?从您的代码和屏幕截图中可以看出,您的变量包含这样一个对象
let source = { source: {
oxxo: { number: 111 }
}}
source.source.oxxo.number
所以你需要像这样访问
let source = { source: {
oxxo: { number: 111 }
}}
source.source.oxxo.number