0

这是我的对象:

     $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"
         }]
     }];
  1. 我正在做一个表格来显示所有内容,我在里面做一个 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>  
    
  2. 我试过过滤 ng-repeat

     | filter: {group: 'Support'}
    

并且不工作

  1. 正如您所看到的,我将对象发送到 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"
     }

似乎还可以?

4

1 回答 1

2

您将分配定义为对象数组

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>
于 2013-08-25T19:48:29.083 回答