这是我的对象:
$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"
}]
}];
我正在做一个表格来显示所有内容,并且在里面进行 hg-repeat,但我不知道如何访问分配的名称和组信息
<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>
我尝试过通过
过滤 ng-repeat| filter: {group: 'Support'}
并且不起作用
正如您所见,我将对象发送到 ng-click
<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>
我正在做的是这个
$scope.sendToDev = function(ticket){
this.ticket.assigned.group = "Support"
}
看起来还可以吗?
最佳答案
您将分配定义为对象数组
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>
关于javascript - ng-repeat 和 javascript 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18432942/