There are two orders in this json array. I need to pull the quantity and price from one internal array (product_id) and from another (name) product name the pivot array is unknown to me, and it is not complete
I try this:
<template v-for="order in orders">
<tr>
<td>{{ order.order_id }}</td>
<td>
<span v-for="product_id in order.product_id">
<span v-for="name in order.name">
{{ name.name }} -
</span>
{{ product_id.quantity }}pc.
Price: {{ product_id.price }}
</span>
</td>
</tr>
</template>
but I get the data in the wrong order:
Product_8 - Product_21 - Product_30-1 pc. Price: 141
Product_8 - Product_21 - Product_30-2 pc. Price: 509
Product_8 - Product_21 - Product_30-1 pc. Price: 399
Product_1 - Product_11 - Product_20-3 pc. Price: 320
Product_1 - Product_11 - Product_20-2 pc. Price: 953
Product_1 - Product_11 - Product_20-1 pc. Price: 911
This is my original json array:
[
{
"order_id":1,
"status":20,
"partner_name":"McLaughlin",
"product_id":[
{
"id":1,
"order_id":1,
"product_id":8,
"quantity":1,
"price":141
},
{
"id":2,
"order_id":1,
"product_id":30,
"quantity":2,
"price":509
},
{
"id":3,
"order_id":1,
"product_id":21,
"quantity":1,
"price":399
}
],
"name":[
{
"id":8,
"name":"Product_8",
"price":141,
"pivot":{
"order_id":1,
"product_id":8
}
},
{
"id":21,
"name":"Product_21",
"price":399,
"pivot":{
"order_id":1,
"product_id":21
}
},
{
"id":30,
"name":"Product_30",
"price":509,
"pivot":{
"order_id":1,
"product_id":30
}
}
]
},
{
"order_id":2,
"status":10,
"partner_name":"Grimes",
"product_id":[
{
"id":4,
"order_id":2,
"product_id":1,
"quantity":3,
"price":320
},
{
"id":5,
"order_id":2,
"product_id":11,
"quantity":2,
"price":953
},
{
"id":6,
"order_id":2,
"product_id":20,
"quantity":1,
"price":911
}
],
"name":[
{
"id":1,
"name":"Product_1",
"price":320,
"pivot":{
"order_id":2,
"product_id":1
}
},
{
"id":11,
"name":"Product_11",
"price":953,
"pivot":{
"order_id":2,
"product_id":11
}
},
{
"id":20,
"name":"Product_20",
"price":911,
"pivot":{
"order_id":2,
"product_id":20
}
}
]
},
Ideally, this would be the case, but the number of products in the order may vary:
<td>{{ order.name[0].name }} </br>
{{ order.product_id[0].quantity }}pc. </br>
Price: {{ order.product_id[0].price }}</td>
<td>{{ order.name[1].name }} </br>
{{ order.product_id[1].quantity }}pc. </br>
Price: {{ order.product_id[1].price }}</td>
<td>{{ order.name[2].name }} </br>
{{ order.product_id[2].quantity }}pc. </br>
Price: {{ order.product_id[2].price }}</td>
Tell me how to correctly extract such data in Vue?