ng repeat&;javascript对象
这是我的目标:ng repeat&;javascript对象,javascript,angularjs,Javascript,Angularjs,这是我的目标: $scope.tickets = [{ title: "Bug 1", number: 1, desc: 'Description #1', assigned: [{ name: "Someone", group: "Development" }] }, { title: "Bug 2",
$scope.tickets = [{
title: "Bug 1",
number: 1,
desc: 'Description #1',
assigned: [{
name: "Someone",
group: "Development"
}]
},
{
title: "Bug 2",
number: 2,
desc: 'Description #1',
assigned: [{
name: "someone2",
group: "Development"
}]
},
{
title: 'Random unknown issue',
number: 3,
desc: 'Description #3',
assigned: [{
name: "Someone3",
group: "Support"
}]
}];
<p class="lead">Development:</p>
<div class="table-responsive">
<table class="table table-striped table-condensed">
<thead>
<tr>
<!-- <th>index</th> -->
<th>#</th>
<th>Title</th>
<th>Description</th>
<th>Group/Assigned</th>
<th>Advanced</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="ticket in tickets">
<td>{{ticket.number}}</td>
<td>{{ticket.title}}</td>
<td>{{ticket.desc}}</td>
<td>{{ticket.assigned.group}} / {{ticket.assigned.name}}</td>
<td>
<button class="btn btn-primary" ng-click="sendToSupport(ticket)">Send to Support</button>
</td>
</tr>
</tbody>
</table>
</div>
<tr ng-repeat="ticket in tickets">
<td>{{ticket.number}}</td>
<td>{{ticket.title}}</td>
<td>{{ticket.desc}}</td>
<td>{{ticket.assigned.group}} / {{ticket.assigned.name}}</td>
<td>
<button class="btn btn-primary" ng-click="sendToSupport(ticket)">Send to Support</button>
</td>
似乎可以吗?您定义的赋值为对象数组
assigned: [{
name: "Someone3",
group: "Support"
}]
将其定义为对象(不带[])或将其作为数组访问
assigned: {
name: "Someone3",
group: "Support"
}
如果确实需要将其作为数组,请使用嵌套的ng repeat,如下所示:
<td><div ng-repeat="assigned in ticket.assigned">{{assigned.group}} / {{assigned.name}}</div></td>
{{assigned.group}/{{assigned.name}
ng应用程序和ng控制器属性在哪里?另外,请上传js文件中的角度声明。ng-app在我的html标记中。我的控制器在div中。你将如何按组进行过滤?ng repeat=“assigned in ticket.assigned | filter:{group:'Support'}”我昨天做了这件事,然后回答了你的问题,我丢弃了一个plunker,它正在工作。再试一次。如果你做不到的话,我今晚就给你一顿痛快。
assigned: {
name: "Someone3",
group: "Support"
}
<td><div ng-repeat="assigned in ticket.assigned">{{assigned.group}} / {{assigned.name}}</div></td>