2017-06-01 6 views
3

オブジェクトの配列にアクセスしようとしていますが、成功しません。 他の記事と回答を読んでください。それでも、それはできません。角:オブジェクトの配列にアクセスできません

は、これが私の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" 

これは、ない成功によってトラックと試みた[ngRepeat:dupes] Duplicates in a repeater誤り を取得し、私の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アイテムにアクセスしようとしている、とイムです。 は、私は...あなたの問題は、あなたが同じであるいくつかのレコードを持っていると思うので、あなたは...いくつかのユニークなフィールドでのようなもの、あなたの繰り返しをtrackする必要があなたに

+2

JavaScriptの有効な使用をあなたに感謝し、あなたのコードをフォーマットしよう... – Hitmands

+1

activeInvoice.invoice_dataはJSONオブジェクトではない配列 'は'この行は正しい私ではありませんあなたがDBからそれを得る方法である –

+0

を推測してください。 – torresito

答えて

1

に感謝:

<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)を..

+0

まず、あなたに感謝します。残念なことに、これはうまくいきませんでした。私のinvoice_dataが間違ってフォーマットされていると思います。 – torresito

+1

オンラインjsonチェッカーとフォーマッターで確認 –

0

SOLVED IT。 jsonは解析をエンコードしましたか?みんな

+1

ニース!できればあなた自身の答えを受け入れることができますか?記録のために :) –

関連する問題