我有一个看起来像这样的数组:
sales = [
[{'Year': 2018, 'Month': 01, 'Sale'; 512}, {'Year': 2018, 'Month': 02, 'Sale'; 1025}, ....],
[{'Year': 2017, 'Month': 01, 'Sale'; 155}, {'Year': 2017, 'Month': 02, 'Sale'; 12}, ....]
]
Run Code Online (Sandbox Code Playgroud)
我想使用 vue 在表格中显示它:
<table class="table table-striped">
<thead>
<tr>
<th>#</th>
<th>2018</th>
<th>2017</th>
</tr>
</thead>
<tbody>
<tr v-for="(sale,i) in sales" :key="i">
<th scope="row">{{ ??? }}</th> //Month
<td>{{ ??? }}</td> //currentYear.Sale
<td>{{ ??? }}</td> //previousYear.Sale
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
不幸的是,我不知道如何遍历我的销售数组以显示在当前年份和上一年的每个表行销售中。
Vla*_*rin 13
<div id="app">
<table class="table table-striped">
<thead>
<tr>
<th>#</th>
<th>2018</th>
<th>2017</th>
</tr>
</thead>
<tbody>
<tr v-for="(sale,i) in sales[0]" :key="i">
<th scope="row">{{ sale.Month }}</th>
<td>{{ sale.Sale }}</td>
<td>{{ sales[1][i].Sale }}</td>
</tr>
</tbody>
</table>
</div>
new Vue({
el: "#app",
data: {
sales: [
[{'Year': 2018, 'Month': 01, 'Sale': 512}, {'Year': 2018, 'Month': 02, 'Sale': 1025}],
[{'Year': 2017, 'Month': 01, 'Sale': 155}, {'Year': 2017, 'Month': 02, 'Sale': 12}]
]
}
})
Run Code Online (Sandbox Code Playgroud)
示例https://jsfiddle.net/mcqwtdgr/