我遇到的问题是,当我尝试删除行时,该功能不起作用。我想要实现的是通过单击红色按钮删除表内的一行。
Link to my plunker code
这就是我在index.html中添加的内容
<button type="button" ng-click="removeRow(row)" class="btn btn-sm btn-danger">
<i class="glyphicon glyphicon-remove-circle"></i>
</button>
这就是我在script.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
关于javascript - 删除表中的一行-AngularJS和FireBase,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35504819/