Javascript 如何循环vuejs中的嵌套数组
我有一些多维数组 我的api响应Javascript 如何循环vuejs中的嵌套数组,javascript,arrays,multidimensional-array,vue.js,Javascript,Arrays,Multidimensional Array,Vue.js,我有一些多维数组 我的api响应 0: name : "name", address : "address" 0: reciepts : ballance : 10, bill : 101, 1: reciepts : ballance : 12, bill : 101
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>
- //这很好用
{{报告。条例草案}
//这张照片什么都没有
{{receipts.bill}}
内部循环不打印任何内容。但是如果我在第二个循环中像{{receipts}}一样打印原始数据,它会打印所有数据。那么,我如何在receipts对象中循环呢?@chrisg已经在评论中给出了答案。然而,由于它隐藏了一点,以下是答案:
<div class="row" v-for="reciept in report.reciepts">{{reciept.bill}}</div>
{{receipt.bill}
请注意,我在访问单个属性时删除了receipt的复数形式。问题示例中的数据结构有点混乱。
receipts
是数组的键值,还是只是一个数组,其中的对象具有receipts
键?您能将响应数据发布为JSON吗?我面临内部循环的问题。我想显示收据数组的所有数据。不通过法案_no@ChrisG它不打印任何内容我猜您需要v-for=“receipts in report.receipts”