javascript - 如何循环遍历vuejs中的嵌套数组
问题描述
我有几个多维数组的数组。
我的 api 响应
0: name : "name",
address : "address"
0:
reciepts :
ballance : 10,
bill : 101,
1:
reciepts :
ballance : 12,
bill : 101,
1: name : "name",
address : "address"
0:
reciepts :
ballance : 13,
bill : 101,
1:
reciepts :
ballance : 14,
bill : 101,
2: name : "name",
address : "address"
0:
reciepts :
ballance : 15,
bill : 101,
1:
reciepts :
ballance : 16,
bill : 101,
我将此数据绑定到一个数组。
this.reportResults=response.data;
在代码中,我正在遍历这个数组,例如
<ul>
<li v-for="report in reportResults"> // this woks fine
<div class="row " style="background-color: #f4fbee;">
<div class="col-md-2">{{report.bill_no}}</div>
</div>
</li>
</ul>
但在这里我想循环浏览收据。所以我只是写了
<ul>
<li v-for="report in reportResults"> // this woks fine
<div class="row " style="background-color: #f4fbee;">
<div class="col-md-2">{{report.bill_no}}</div>
</div>
<div class="row" v-for="reciepts in report"> // this print nothing
{{reciepts.bill}}
</div>
</li>
</ul>
内循环不打印任何内容。但是,如果我在第二个循环中打印原始数据,例如 {{reciepts}},它会打印所有数据。那么我怎样才能遍历收据对象呢?
解决方案
@Chris G 已经在评论中发布了答案。但是,由于它有点隐藏,所以这是答案:
<div class="row" v-for="reciept in report.reciepts">{{reciept.bill}}</div>
请注意,在访问单个属性时,我已经删除了 reciept 的复数形式。
推荐阅读
- python - 使用动态创建的布尔掩码时,numpy“TypeError:输入类型不支持 ufunc 'bitwise_and'”
- python - google-api-core 1.1.2 有要求 setuptools>=34.0.0
- java - 按字段对一组元素进行排序
- python - 对`_imp__的未定义引用
- java - 不一致的状态比较 Java
- python - 如何在单次遍历中找到python链表中的中间元素?
- java - jsp文件中的if语句进不去
- arduino - 在没有以太网屏蔽的情况下将数据从 arduino 发送到 sql server
- javascript - 处理 JS 计算的 CSS 值而不使用内联或嵌入样式
- c++ - 单独库中的类成员函数定义,以及链接依赖项