vue.js - 使用 VUE 在数组中显示数组
问题描述
如何在 VUE 中显示数组内部的数组?
我用下面的代码试过了,但似乎不对。
<table class="table table-border">
<thead>
<tr>
<th v-for="(name, index) in attributes" v-html="attributes[index].name"></th>
</tr>
</thead>
<tr v-for="(values, index) in attributes">
<td v-for="(name, index) in values" v-html="values[index].name"></td>
</tr></table>
解决方案
如果没有看到对象的结构,很难完全帮助您,另外您还想实现什么> 我看到了设置表格的基础知识,但是需要将数组的哪一部分应用于表格?
如果我有下面的对象(为了清楚起见,Typescript Type):
interface Parent {
ID: string,
Name: string,
Age: number,
ParentOf: Array<Child>
}
interface Child{
Name: string,
FavoriteNumbers: Array<number>
}
下面我将遍历父母的孩子,以发现每个孩子最喜欢的数字。
<div>
<div v-for="(child, index) in Parent.ParentOf">
<p>{{Parent.Name}} <br />
{{child.Name}} </p>
<ul>
<li v-for="number in child.FavoriteNumbers">
Favorite Number: {{number}} <!--We are iterating through an array of an array here -->
</li>
</ul>
</div>
</div>
推荐阅读
- python - 客户用户模型错误;ModuleNotFoundError:没有名为“帐户”的模块
- r - 如何禁用 R Datatable 中特定列的双击反应性
- python - time.time() 浮动对象没有属性错误
- regex - Ansible 从文件中复制 ssh 公钥,在 uri 调用中使用
- python - 熊猫,扩展数据框系列
- .net - 我们可以将 WEBSITE_LOAD_USER_PROFILE=1 添加到 web.config
- azure-devops - Azure DevOps:将团队成员添加到新团队/区域
- python - 错误 NOT NULL 约束失败:使用 3 个模型(外键)自定义表单 django-all-auth
- c - gcc-10.0.1 特定的段错误
- java - 从 SwingWorker 调用 done 方法时是否必须使用 Runnable.run