- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直坚持使用 ng-repeat 显示数据。我唯一能做的就是显示两个对象之一。每个客户可以有多个用户。我正在尝试在具有 CustomerId 的表中显示用户。 Working plunkr
app.controller('MainCtrl', function ($scope) {
var json = [
{
"CustomerId": "12xsd-344-fv23", "CompanyName": "ConocoPhillips",
"Address": "1234 Main St", "City": "Redmond", "State": "WA", "Zip": "10999",
"Email": "debra@example.com",
"Users": [
{
"FirstName": "Rudy", "LastName": "Sanchez", "CustomerId": "12xsd-344-fv23", "Customer": null,
"Email": "admin@energy.com", "EmailConfirmed": true, "PasswordHash": "AGtuCXr",
"SecurityStamp": "b0fca140", "PhoneNumber": null, "PhoneNumberConfirmed": false, "TwoFactorEnabled": false,
"LockoutEndDateUtc": null, "LockoutEnabled": false, "AccessFailedCount": 0, "Roles": [], "Claims": [], "Logins": [],
"Id": "49b5", "UserName": "admin"
},
{
"FirstName": "Troy", "LastName": "Benbow", "CustomerId": "12xsd-344-fv23", "Customer": null,
"Email": "tbenbow@yahoo.com", "EmailConfirmed": true, "PasswordHash": "AM8wL+iHaSG",
"SecurityStamp": "14f1483a-2e6f-41da-8307-a6c5945984a9", "PhoneNumber": null, "PhoneNumberConfirmed": false, "TwoFactorEnabled": false,
"LockoutEndDateUtc": null, "LockoutEnabled": true, "AccessFailedCount": 0, "Roles": [], "Claims": [], "Logins": [],
"Id": "9985b820-a45", "UserName": "tbenbow"
}
]
},
];
$scope.customers = json;
});
最佳答案
因为 CustomerId
也是 User
的属性,您可以在 Controller ,然后在表中循环它们:
$scope.users = [];
for(var i = 0; i < $scope.customers.length; i++) {
for(var j = 0; j < $scope.customers[i].Users.length; j++) {
//now you have access to customer properties with $scope.customers[i]
var user = $scope.customers[i].Users[j];
//example of adding CompanyName property
user.CompanyName = $scope.customers[i].CompanyName;
//add user to $scope.users
$scope.users.push(user);
}
}
然后只是 ng-repeat
users
:
<tr ng-repeat="user in users">
<td>{{user.FirstName}} {{user.LastName}}</td>
<td>{{user.UserName}}</td>
<td>{{user.Email}}</td>
<td>{{user.CustomerId}}</td>
<td>{{user.CustomerName}}</td>
</tr>
这是一个 updated plunker .
事实上,即使您需要 json
的父 Customer
部分的属性,您也可以将该属性添加到 users
数组中被重复。
为 View 准备数据通常会简化模板技巧(例如必须使用额外的 ng-repeat
ed 元素构建表格。IMO,这是更可取的。 p>
关于json - 如何使用 ng-repeat 深入分析 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28268909/
在开始本文前先考虑以下一个问题 在不使用任何带有自动补全功能IDE的情况下,如何获取一个数组的长度?以及,如何获取一个字符串的长度? 这个问题我问过不同水平的程序员,包括初级和中级水平的。他们都
spool--导出sql语句结果集 SQL>spool c:\testsql.sql SQL>SELECT * FROM table_name; SQL>spool off;
在面向对象的C++语言中,虚函数(virtual function)是一个非常重要的概念。因为它充分体现 了面向对象思想中的继承和多态性这两大特性,在C++语言里应用极广。比如在微软的MFC类库中,
在查询语句中使用 NOLOCK 和 READPAST 处理一个数据库死锁的异常时候,其中一个建议就是使用 NOLOCK 或者 READPAST 。有关 NOLOCK 和 READPAST
我正在尝试使用 espn 公共(public) API 并尝试使用他们的 json 来访问 NFL 球员信息。 我成功访问的 json 如下所示: { "sports": [ {
前面跟小伙伴们分享了 SpringMVC 一个大致的初始化流程以及请求的大致处理流程,在请求处理过程中,涉及到九大组件,分别是: HandlerMapping Hand
Automatic Workload Repository 是 10g 引入的一个重要组件 存贮着近期一段时间内数据库活动状态的详细信息、信息保留默
我一直坚持使用 ng-repeat 显示数据。我唯一能做的就是显示两个对象之一。每个客户可以有多个用户。我正在尝试在具有 CustomerId 的表中显示用户。 Working plunkr app.
对我来说,下面的 Java 代码是完全有效的,风格很好: enum Side { LEFT, RIGHT }; ... Side side = ...; switch (side) { case LE
我是一名优秀的程序员,十分优秀!