Angular:无法访问对象中的数组

时间:2017-06-01 11:00:19

标签: angularjs

我尝试访问对象中的数组,但没有成功。 在这里阅读其他帖子和答案,仍然无法做到。

这是我的obj:activeInvoice

balance_due:
"-72.26"
customer_id
:
"4"
customerpm_id
:
"1244"
date
:
"2017-03-02 04:23:18"
id:
"10334"
invoice_data:
"{"subtotal":72.26,"items":[{"storeid":"148","title":"MONTEBELLO","qty":1,"price":"1.9900","type":"payment"},{"storeid":"149","title":"Gold Elements - Store","qty":1,"price":"66.2900","type":"payment"},{"storeid":"860","title":"Gold Elements - Cart","qty":1,"price":"1.9900","type":"payment"},{"storeid":"1805","title":"Repeat the Heat 2","qty":1,"price":"1.9900","type":"payment"},{"storeid":"2867","title":"office","qty":1,"price":"0.0000","type":"payment"}]}"
invoice_type
:
"monthly_subscription"
status
:
"0"

这是我的HTML

<table class="table dark">
  <thead>
  <tr>
    <th>#</th>
    <th>Item</th>
    <th>QTY</th>
    <th>Price (USD)</th>
  </tr>
  </thead>
  <tbody>
  <tr ng-repeat="invoice in activeInvoice.invoice_data">
    <td class="text-center"></td>
    <td class="text-center" ng-repeat="data in invoice.items">{{data.title}}</td>
    <td class="text-center"></td>
    <td class="text-center"></td>
  </tr>
  </tbody>
</table>

尝试访问invoice_data项目,并且我收到[ngRepeat:dupes] Duplicates in a repeater错误 尝试跟踪,没有成功。 谢谢

2 个答案:

答案 0 :(得分:1)

我认为你的问题是你有一些相同的记录...所以你需要track你的重复一些独特的领域......如:

<tr ng-repeat="invoice in activeInvoice.invoice_data track by $index">
  <td class="text-center"></td>
  <td class="text-center" ng-repeat="data in invoice.items track by item.storeid">{{data.title}}</td>
  <td class="text-center"></td>
  <td class="text-center"></td>
</tr>

IF YOUR STOREID IS A UNIQUE PK (so you can't have 2 storeid equal) ...

答案 1 :(得分:0)

解决了它。做了json编码解析。谢谢你们