大家好,我正在从REST-API检索大型JSON。我想在一个表列中显示2个数组中的值,但它对我不起作用。 我需要所有line_items.quantity +“您必须支付:” + line_items.total在表的一列中。 希望有人能帮忙。
{
"id": 184,
"parent_id": 0,
"number": "184",
"order_key": "wc_order",
"created_via": "checkout",
"version": "3.6.2",
"status": "processing",
"currency": "EUR",
"date_created": "2019-05-12T21:43:47",
"date_created_gmt": "2019-05-12T19:43:47",
"date_modified": "2019-05-12T21:43:47",
"date_modified_gmt": "2019-05-12T19:43:47",
"discount_total": "0.00",
"discount_tax": "0.00",
"shipping_total": "0.00",
"shipping_tax": "0.00",
"cart_tax": "4.48",
"total": "28.00",
"total_tax": "4.48",
"prices_include_tax": true,
"customer_id": 2,
"customer_ip_address": "9",
"customer_user_agent": "Mozk",
"customer_note": "",
"billing": {
"first_name": "lana",
"last_name": "NummerZwo",
"company": "",
"address_1": "l12",
"address_2": "",
"city": "bochum",
"state": "",
"postcode": "44237",
"country": "DE",
"email": "kl",
"phone": "",
"title": "1"
},
"shipping": {
"first_name": "lana",
"last_name": "NummerZwo",
"company": "",
"address_1": "Sach",
"address_2": "",
"city": "bochum",
"state": "",
"postcode": "44237",
"country": "DE",
"title": "1",
"parcelshop": false,
"parcelshop_post_number": ""
},
"payment_method": "cod",
"payment_method_title": "Per Nachnahme",
"transaction_id": "",
"date_paid": null,
"date_paid_gmt": null,
"date_completed": null,
"date_completed_gmt": null,
"cart_hash": "k",
"meta_data": [
{
"id": 1967,
"key": "_billing_title",
"value": "1"
},
{
"id": 1968,
"key": "_shipping_title",
"value": "1"
},
{
"id": 1969,
"key": "is_vat_exempt",
"value": "no"
}
],
"line_items": [
{
"id": 6,
"name": "product 2 - blue",
"product_id": 68,
"variation_id": 69,
"quantity": 4,
"tax_class": "",
"subtotal": "11.76",
"subtotal_tax": "2.24",
"total": "11.76",
"total_tax": "2.24",
"taxes": [
{
"id": 34,
"total": "2.235294",
"subtotal": "2.235294"
}
],
"meta_data": [
{
"id": 63,
"key": "farbe",
"value": "red"
},
{
"id": 64,
"key": "_units",
"value": ""
},
{
"id": 65,
"key": "_delivery_time",
"value": ""
},
{
"id": 66,
"key": "_item_desc",
"value": ""
},
{
"id": 67,
"key": "_unit_price",
"value": ""
}
],
"sku": "",
"price": 2.9411765
},
{
"id": 7,
"name": "product - red",
"product_id": 68,
"variation_id": 70,
"quantity": 2,
"tax_class": "",
"subtotal": "7.56",
"subtotal_tax": "1.44",
"total": "7.56",
"total_tax": "1.44",
"taxes": [
{
"id": 34,
"total": "1.436975",
"subtotal": "1.436975"
}
],
"meta_data": [
{
"id": 77,
"key": "farbe",
"value": "blue"
},
{
"id": 78,
"key": "_units",
"value": ""
},
{
"id": 79,
"key": "_delivery_time",
"value": ""
},
{
"id": 80,
"key": "_item_desc",
"value": ""
},
{
"id": 81,
"key": "_unit_price",
"value": ""
}
],
"sku": "",
"price": 3.7815125
},
{
"id": 8,
"name": "product - red",
"product_id": 77,
"variation_id": 78,
"quantity": 1,
"tax_class": "",
"subtotal": "4.20",
"subtotal_tax": "0.80",
"total": "4.20",
"total_tax": "0.80",
"taxes": [
{
"id": 34,
"total": "0.798319",
"subtotal": "0.798319"
}
],
"meta_data": [
{
"id": 91,
"key": "farbe",
"value": "blue"
},
{
"id": 92,
"key": "_units",
"value": ""
},
{
"id": 93,
"key": "_delivery_time",
"value": ""
},
{
"id": 94,
"key": "_item_desc",
"value": ""
},
{
"id": 95,
"key": "_unit_price",
"value": ""
}
],
"sku": "",
"price": 4.201681
}
],
"tax_lines": [
{
"id": 10,
"rate_code": "DE-MWST. DE-1",
"rate_id": 34,
"label": "MwSt. DE",
"compound": false,
"tax_total": "4.48",
"shipping_tax_total": "0.00",
"meta_data": []
}
],
"shipping_lines": [
{
"id": 9,
"method_title": "Abholung vor Ort",
"method_id": "local_pickup",
"instance_id": "3",
"total": "0.00",
"total_tax": "0.00",
"taxes": [],
"meta_data": [
{
"id": 101,
"key": "Positionen",
"value": "product blue; 4, product - red × 2, product2 - blue × 1"
}
]
}
],
"fee_lines": [],
"coupon_lines": [],
"refunds": [],
"parcel_delivery_opted_in": "",
"direct_debit": {
"holder": "",
"iban": "",
"bic": "",
"mandate_id": ""
},
"_links": {
"self": [
],
"collection": [
],
"customer": [
]
}
},
这是JSON一部分的样子。 我正在使用此代码来打印我需要的信息:
var customer_table = $('#customer_table').DataTable({
ajax: {
"url":"www.example.de/REST-API",
"dataSrc": ""
},
"columns": [
{ "data": "id" },
{"data":"billing.last_name",
"className":"left",
"render":function(data, type, full, meta){
return full.billing.first_name +" "+ full.billing.last_name;
}
},
{ "data":"billing.last_name",
"className":"left",
"render":function(data, type, full, meta){
return full.line_items[0].quantity +"x "+ full.line_items[0].total;
}
},
{ "data": "billing.first_name"},
{ "data": "line_items[, ].name"},
{ "data": "line_items[, ].quantity" },
{for (var i = 0; i < results.data.length; i++) {
console.log( results.data.line_items[i].quantity + results.data.line_items[i].total);
}}
我真的不知道如何在这个大JSON中循环: 我需要这部分的帮助:
{for(var i = 0; i