[英]How to select from list of items rendered using ng-repeat
I am having arrays of array as response我有数组作为响应
[
[
"i-091a5dosdobs2",
"t2.nano",
"running"
],
[
"i-03dd8duhud9",
"t2.micro",
"running"
]
]
I am using ng-repeat and rendering the data into table我正在使用 ng-repeat 并将数据渲染到表中
<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>
I want button in all the rows which can able to close that particular instance but how to do it ?我想要所有行中的按钮都可以关闭该特定实例,但该怎么做? in json we can do with key.
在 json 中,我们可以使用 key。 How can I do it here ?
我怎么能在这里做?
If you need a unique key to close the row by it.如果您需要一个唯一的键来关闭它的行。 Then you can use
然后你可以使用
<tr ng-repeat="(key, value) in data">
so the key will point to the index of the array 0, 1, 2, ...所以键将指向数组 0, 1, 2, ...
You only need to pass the ec2 instance ID which is d[0]
您只需要传递 ec2 实例 ID,即
d[0]
<button class="btn btn-primary" ng-click="close(d[0])">Close</button>
and your close function would be like你的关闭功能就像
$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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.