I've got a JSON feed with some tabular data and I'm using Vue.js to show a HTML table:
<tr v-for="row, index in content">
<td class="index" v-text="index + 1"></td>
<td v-for="column in row" v-text="column"></td>
</tr>
This feed returns an array for each row, but some rows have named keys. With this simple foreach-loop it ignores the keys and this will generate a table that doesn't show the data in a correct way.
How can I use the keys to generate the table? I've looked into getting the highest value from the keys and use Array.fill()
, but I think there must be a better way.
This is my data:
{
"content": [
[
"",
"In scope:",
"Not in scope:"
],
[
"Cars",
"",
"X"
],
[
"Bikes",
"X",
""
],
{
"0": "Houses",
"2": "X"
}
]
}
Please note that this is fictional data, the actual data can vary so I can't have a solution with a fixed number of columns.
Actual output:
| | In scope: | Not in scope: |
|--------|-----------|---------------|
| Cars | | X |
| Bikes | X | |
| Houses | X |
Expected output:
| | In scope: | Not in scope: |
|--------|-----------|---------------|
| Cars | | X |
| Bikes | X | |
| Houses | | X |