Javascript AngularJS—计算JSON数组的长度
我有一组JSON数据,其中我试图计算数组的长度(Infos): 我的JSON:Javascript AngularJS—计算JSON数组的长度,javascript,json,angularjs,angularjs-scope,angularjs-ng-repeat,Javascript,Json,Angularjs,Angularjs Scope,Angularjs Ng Repeat,我有一组JSON数据,其中我试图计算数组的长度(Infos): 我的JSON: "Association": { "Items": [ { "AssocName": { "SurName": "BLOGGS", "Title": "MR", "ForeName": "HAPPY" }, "Deta
"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>
{[{associations.AssocName.Title}]}
{[{associations.AssocName.ForeName}]}
{[{associations.AssocName.姓氏}]}
{[{associations[$index].Details.Infos.length}]}的详细信息
但似乎没有显示任何价值。。。标题、名字和姓氏按预期显示。您不需要索引
<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>
{[{associations.AssocName.Title}]}
{[{associations.AssocName.ForeName}]}
{[{associations.AssocName.姓氏}]}
{[{associations.Details.Infos.length}]}的详细信息
只需按如下所示尝试这种方法
<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>
{{associations.AssocName.Title}
{{associations.AssocName.ForeName}}
{{协会.协会名称.姓氏}
详细信息的[{associations.Details[0].Infos.length}]
@Blackhole-详细信息中缺少[0]此答案。。。见尼迪什的答案。