删除表中的行 - AngularJS 和 FireBase

Deleting a row inside a table - AngularJS and FireBase

本文关键字:AngularJS FireBase 删除      更新时间:2023-09-26

我遇到的问题是当我尝试删除一行时该功能不起作用。我试图实现的是通过单击红色按钮删除表中的一行。

链接到我的 plunker 代码

这是我在索引中添加的内容.html

    <button type="button" ng-click="removeRow(row)" class="btn btn-sm btn-danger">
      <i class="glyphicon glyphicon-remove-circle"></i>
    </button> 

这是我在脚本中添加的内容.js

  $scope.removeRow = function removeRow(item) {
    var index = $scope.myData.indexOf(item);
    if (index !== -1) {
        $scope.myData.splice(index, 1);
    }
}

你传递了错误的对象。

ng-click="removeRow(row)"

如果要从customers中删除数据,则必须传递customer

在 js 中,您正在尝试从$scope.myData中删除数据而不是$scope.customers . $scope.myData 是一个对象,对象没有方法名称.splice()

像这样尝试

.JS

  $scope.removeRow = function removeRow(item) {
    var index = $scope.customers.map(function(x){return x.CustomerPlateNumber;}).indexOf(item.CustomerPlateNumber);
    if (index !== -1) {
        $scope.customers.splice(index, 1);
    }
}

.HTML

<button type="button" ng-click="removeRow(customer)" class="btn btn-sm btn-danger">

DEMO