我有陣列作為回應
[
[
"i-091a5dosdobs2",
"t2.nano",
"running"
],
[
"i-03dd8duhud9",
"t2.micro",
"running"
]
]
我正在使用 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>
我想要所有行中的按鈕都可以關閉該特定實體,但如何操作?在 json 中,我們可以使用 key。我怎么能在這里做?
uj5u.com熱心網友回復:
如果您需要一個唯一的鍵來關閉它的行。然后你可以使用
<tr ng-repeat="(key, value) in data">
所以鍵將指向陣列 0, 1, 2, ...
uj5u.com熱心網友回復:
您只需要傳遞 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
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/341621.html
