【发布时间】:2021-06-23 09:24:00
【问题描述】:
我有这个JSON-array,它看起来像这样:
"data": {
"cells": [
[
{
"rowIndex": 0,
"columnIndex": 0,
"value": "<p>This is some value</p>",
"type": "th",
"scope": "col"
},
{
"rowIndex": 0,
"columnIndex": 1,
"value": "<p>Another value</p>",
"type": "th",
"scope": "col"
}
],
[
{
"rowIndex": 1,
"columnIndex": 0,
"value": "<p>Blabla blabla</p>",
"type": "td",
"scope": null
},
{
"rowIndex": 1,
"columnIndex": 1,
"value": "<p>Lorem ipsum</p>",
"type": "td",
"scope": null
}
]
],
}
现在我想在我的vuejs-app 的表格中呈现这些数据,所以我尝试这样做:
首先通过计算值获取数据:
computed: {
tableData() {
return this.content.data.cells;
},
},
然后通过表格渲染数据:
<table>
<tr v-for="cell in tableData" :key="cell.id">
<template v-if="cell.type === 'th'">
<th v-for="header in cell" :key="header">
{{ header.value }}
</th>
</template>
<template v-if="cell.type === 'td'">
<td v-for="celldata in cell" :key="celldata">
{{ celldata.value }}
</td>
</template>
</tr>
</table>
但这什么也没显示,字段只是空的。我做错了什么?
【问题讨论】:
标签: javascript vue.js