如何从使用 ng-repeat 呈现的项目列表中 select

How to select from list of items rendered using ng-repeat

我有数组数组作为响应

[
   [
     "i-091a5dosdobs2",
     "t2.nano",
     "running"
   ],
   [
     "i-03dd8duhud9",
     "t2.micro",
     "running"
   ]
]

我正在使用 ng-repeat 并将数据渲染到 table

<tbody>
  <tr ng-repeat="datas in data" >
   <td ng-repeat="d in datas">
    {{d}}
   </td>
   <td>
    <button class="btn btn-primary" ng-click="close(d)">Close</button>
   </td>
  </tr>
  </tbody>

我想要所有行中的按钮都可以关闭该特定实例,但该怎么做? 在 json 中,我们可以使用密钥。我怎么能在这里做?

如果您需要一个唯一键来关闭行。然后你可以使用

<tr ng-repeat="(key, value) in data">

因此键将指向数组 0, 1, 2, ...

的索引

你只需要传递ec2实例ID即d[0]

<button class="btn btn-primary" ng-click="close(d[0])">Close</button>

你的关闭函数就像

$scope.close = function(id) {
   // factory send ajax to close the instance ... then
   let index = $scope.data.findIndex((i)=> i[0]===id)
   $scope.data.splice(index,1); // this would remove the item from your table
}