AngularJS - 如何访问数组中的对象数组

AngularJS - How to access an array of objects within an array

在 c# 中,我正在创建一个包含对象数组的数组并将其传递给 Angular。

Angular 收到:

$scope.accounts = data.items;

在我的 cshtml 中,我可以很好地访问这些值:

<td>{{account.name}}</td>
<td>{{account.primaryAccountManager}}</td>
<td>{{account.secondaryAccountManager}}</td>

但不是:

 <td>{{account.subscriptions.expirationDate}}</td>

我需要做什么才能获得嵌套数组中的到期日期?

您需要使用 [ng-repeat] 指令在数组上循环。

试试看

<div ng-repeat="subscription in account.subscriptions">
  {{subscription.expirationDate}}
</div>

别忘了查看 angular 文档 https://docs.angularjs.org/api/ng/directive/ngRepeat

如果您在 ng-repeat 中,请使用:

<td>{{account.subscriptions[$index].expirationDate}}</td>