I get the data from server something like this way:
"cells": [
{
"consultingBudgetHeadName": "Available hours",
"value": 1806,
"valueMap": "1 806"
},
{
"consultingBudgetHeadName": "Available customer hours",
"value": 1773.2,
"valueMap": "1 773,20"
},
{
"consultingBudgetHeadName": "Absence hours",
"value": 32.8,
"valueMap": "32,80"
},
{
"consultingBudgetHeadName": "Available hours project",
"value": -7092.8,
"valueMap": "-7 092,80"
},
{
"consultingBudgetHeadName": "Average price",
"value": 0,
"valueMap": "0"
},
{
"consultingBudgetHeadName": "Agreement hours",
"value": 8866,
"valueMap": "8 866"
},
{
"consultingBudgetHeadName": "Utilization agreements %",
"value": 500,
"valueMap": "500"
}
]
Now, if I render a list this way:
<template v-for="(cell, index) in cells">
<li>
{{ cell.consultingBudgetHeadName }}
</li>
</template>
It will show the output this way:
- Available hours
- Available customer hours
- Absence hours
- Available hours project
- Average price
- Agreement hours
- Utilization agreements %
But I need the order in a different way than the order of the array. I want my order will be like this:
- Available hours
- Absence hours
- Available customer hours
- Agreement hours
- Available hours project
- Average price
- Utilization agreements %
So, instead of dynamic rendering, I took the index of the array element and render the element this way:
<ul v-for="(row, rowIndex) in data.rows">
<li>{{ row.cells[0].consultingBudgetHeadName }}</li>
<li>{{ row.cells[2].consultingBudgetHeadName }}</li>
<li>{{ row.cells[1].consultingBudgetHeadName }}</li>
<li>{{ row.cells[5].consultingBudgetHeadName }}</li>
<li>{{ row.cells[3].consultingBudgetHeadName }}</li>
<li>{{ row.cells[4].consultingBudgetHeadName }}</li>
<li>{{ row.cells[6].consultingBudgetHeadName }}</li>
</ul>
But I don't think this would be a good idea as index number can be changed at the database any time. So, what's the good way to achieve those?
consultingBudgetHeadNamefield orvaluefield in cells array?valueMap. I usedconsultingBudgetHeadNamein the post as simplicity so that it will be understandable.consultingBudgetHeadId) by the way: codesandbox.io/s/…