【发布时间】:2015-08-13 19:54:42
【问题描述】:
我什至无法弄清楚这是怎么可能的
当我这样做时:
console.error(order.Items[i]);
我明白了:
{ ItemURL: '',
IsBundle: false,
GiftTaxPrice: '0',
GiftPrice: '0',
GiftNotes: null,
GiftMessage: null,
RecyclingFee: 0,
ShippingTaxPrice: 0,
ShippingPrice: 6,
TaxPrice: 0,
UnitPrice: 3,
Quantity: 1,
Title: 'HICKIES TEST PRODUCT',
Sku: 'PLSB_TEST_PRODUCT',
SiteListingID: '30000418',
SiteOrderItemID: '',
ProductID: 72176,
OrderID: 100152,
ProfileID: 12021605,
ID: 156,
CustomFields: [],
Adjustments: [],
FulfillmentItems: [],
Promotions: [] }
但由于某种原因,当我尝试使用
访问 Skuconsole.error(order.Items[i].Sku);
我明白了:
undefined
由于某种原因神奇地
console.error(order.Items[i].Quantity);
或
console.error(order.Items[i].UnitPrice);
打印:
1
和
3
分别
---编辑
根据要求
for (var i = 0; i < order.Items.length; i++) {
formatedOrder['Subtotal'] += parseInt(order.Items[i].Quantity) * parseFloat(order.Items[i].UnitPrice);
console.error(order.Items[i]);
console.error(order.Items[i].Sku);
console.error(order.Items[i]['Sku']);
formatedOrder["OrderLines"].push({
"Product": order.Items[i].Sku,
"Quantity": parseInt(order.Items[i].Quantity),
"Price": parseFloat(order.Items[i].UnitPrice)
});
}
根据请求的项目数组:
[{ ItemURL: '',
IsBundle: false,
GiftTaxPrice: '0',
GiftPrice: '0',
GiftNotes: null,
GiftMessage: null,
RecyclingFee: 0,
ShippingTaxPrice: 0,
ShippingPrice: 6,
TaxPrice: 0,
UnitPrice: 3,
Quantity: 1,
Title: 'HICKIES TEST PRODUCT',
Sku: 'PLSB_TEST_PRODUCT',
SiteListingID: '30000418',
SiteOrderItemID: '',
ProductID: 72176,
OrderID: 100152,
ProfileID: 12021605,
ID: 156,
CustomFields: [],
Adjustments: [],
FulfillmentItems: [],
Promotions: [] }]
【问题讨论】:
-
什么是“i”,它是如何被赋值的?如果您共享更多代码,您将获得更好的结果。
-
出于兴趣,你会从 console.error(order.items[i]['Sku']) 得到什么?
-
代码位于随机函数中,用于重新格式化对象以提交给专有 api。老实说,我认为我正在失去理智,这段代码怎么会不起作用。以及 console.error(order.Items[i]['Sku']); 会发生什么的问题。输出仍未定义
-
您的代码有效,这是一个演示:jsfiddle.net/hvzpdan2
-
同意ochi。看到这个jsfiddle.net/0vpe6cxv。
标签: javascript node.js express