从这个order
对象中,我想从products
数组中的每个对象中提取一个特定的属性。
var order = {
"products": [
{
"product_name":"Name",
"product_sku":"000000075266",
"pricesUnformatted":5130,
"prices":"5.130 EUR",
"subtotal":5130,
"subtotal_tax_amount":0,
"subtotal_discount":0,
"subtotal_with_tax":5130,
"quantity":18
},
{
"product_name":"Name2",
"product_sku":"000000072312",
"pricesUnformatted":369,
"prices":"369 EUR",
"subtotal":369,
"subtotal_tax_amount":0,
"subtotal_discount":0,
"subtotal_with_tax":369,
"quantity":1
}
],
"totalProduct":19,
"billTotal":"<div class='cart_left'>TotalPrice<\/div> : <strong>6.826 EUR<\/strong>",
"dataValidated":false,
"totalProductTxt":"<div class='cart_left'>Quantity<\/div> <div class='cart_right'><strong>19<\/strong><\/div>"
}
因此,我想从这个对象中获取“subtotal_with_tax”项目,然后对它们求和,当然打印结果,因为“billTotal”包含我不需要的运费,在我得到这个之前我不能修改代码目的。
我试图让它工作,但我被困在这一点上,因为我不知道如何定位特定项目的价值,比如在这种情况下 "subtotal_with_tax" :
$.each(order.products, function(key, val) {
$.each(val, function(key, val) {});
});