0

我有一組JSON數據的,並在其中,我試圖計算的陣列的長度(相關信息):AngularJS - JSON陣列的計算長度

我的JSON:

"Association": { 
    "Items": [ 
     { 
      "AssocName": { 
       "SurName": "BLOGGS", 
       "Title": "MR", 
       "ForeName": "HAPPY" 
      }, 
      "Details": [ 
       { 
        "Name": { 
         "SurName": "BLOGGS", 
         "Title": "MR", 
         "ForeName": "HAPPY" 
        }, 
        "Infos": [ 
         { 
         //Some Data 
         //Some Data 
         //Some Data 
         }, 
         { 
         //Some Data 
         //Some Data 
         //Some Data 
         }, 
         { 
         //Some Data 
         //Some Data 
         //Some Data 
         }, 
         { 
         //Some Data 
         //Some Data 
         //Some Data 
         } 
        ] 
       } 
      ] 
     }, 
     { 
      "AssocName": { 
       "SurName": "BLOGGS", 
       "Title": "MRS", 
       "ForeName": "BLUE" 
      }, 
      "Details": [ 
       { 
        "Name": { 
         "SurName": "BLOGGS", 
         "Title": "MRS", 
         "ForeName": "BLUE" 
        }, 
        "Infos": [ 
         { 
         //Some Data 
         //Some Data 
         //Some Data 
         }, 
         { 
         //Some Data 
         //Some Data 
         //Some Data 
         }      
        ] 
       } 
      ] 
     } 
    ] 
} 

我HTML:

<tr ng-repeat-start="associations in Association.Items track by $index"> 
    <td> 
     {[{associations.AssocName.Title}]} 
     {[{associations.AssocName.ForeName}]} 
     {[{associations.AssocName.SurName}]} 
    </td> 
    <td> 
     {[{ associations[$index].Details.Infos.length }]} of Details 
    </td> 
</tr> 

但似乎沒有顯示valus ...標題,姓名和姓氏顯示如預期。

回答

1

剛剛嘗試了這種方式如下圖所示

Working Demo

<table> 
<tr ng-repeat="associations in Association.Items"> 
    <td> 
     {{associations.AssocName.Title}} 
     {{associations.AssocName.ForeName}} 
     {{associations.AssocName.SurName}} 
    </td> 
    <td> 
     [{{associations.Details[0].Infos.length}}] of Details 
    </td> 
</tr> 
</table> 
+0

這是行得通的 - 謝謝。 – 2014-09-01 13:57:20

-1

你不需要索引

<tr ng-repeat-start="associations in Association.Items"> 
    <td> 
     {[{associations.AssocName.Title}]} 
     {[{associations.AssocName.ForeName}]} 
     {[{associations.AssocName.SurName}]} 
    </td> 
    <td> 
     {[{ associations.Details.Infos.length }]} of Details 
    </td> 
</tr> 
+0

試過了,沒有任何顯示。 – 2014-09-01 13:22:12

+0

@Blackhole - 這個答案在細節中缺少[0] ...查看Nidhish的回答。 – 2014-09-01 13:57:50