从列表中删除项过滤之后 [英] Remove item from list after filtering
问题描述
我有以下问题:
我已经创建一个列表,允许用户删除列表中的项目,如下:
I've create a list that allow the user to delete an item from list, as following:
在上垃圾桶图标用户点击,该项目正常删除。
当用户使用在顶部的过滤器的问题是
When user click on trash icon, the item is removed normally. The problem is when the user uses the filter on top.
在这种情况下,如果我删号6565(筛选列表索引4在最初的名单,1),删除的项目是原来名单上的索引1,导致与数#删除寄存器564456
In that case, if I delete the number 6565 (index 4 in original list, 1 on filtered list), the item deleted is on index 1 on original list, resulting on delete the register with number #564456
这是我上单击删除电话:
This is my delete call on click:
$scope.deleteOwn = function (uuid) {
console.log(uuid);
var coupon = $scope.ownsCoupons[uuid];
Coupon.delete({'id' : coupon.uuid}, function () {
$scope.ownsCoupons.splice(uuid, 1);
});
}
这是我的HTML模板:
And this is my html template:
<td><a href="" ><i class="icon-trash" ng-click="deleteOwn($index)"></i></a></td>
我也尝试使用code: $ scope.ownsCoupons.splice(优惠券,1);
无功而返
有谁知道如何解决这个问题?
Does anyone know how to fix that?
我已经用下面的参考codeD:<一href=\"http://stackoverflow.com/questions/14250642/angularjs-how-to-remove-and-item-from-scope\">AngularJS如何从范围
I've coded using the following reference: AngularJS How to remove and Item from scope
我创建了一个Plunker这样:<一href=\"http://plnkr.co/edit/Fhxp6uZyTJCY05CAQ7yA?p=$p$pview\">http://plnkr.co/edit/Fhxp6uZyTJCY05CAQ7yA?p=$p$pview
I've created a Plunker to this: http://plnkr.co/edit/Fhxp6uZyTJCY05CAQ7yA?p=preview
推荐答案
正如@ pkozlowski.opensource提到的,你不能依赖于 $指数
来确定一个项目在这种方式的阵列。我会做以下更改:
As mentioned by @pkozlowski.opensource, you can't depend on $index
to identify an item in an array in this way. I would make the following changes:
HTML
<td><a ng-click="deleteWish(coupon)"><i class="icon-trash"></i></a></td>
JS:
$scope.deleteWish = function (coupon) {
var index = $scope.coupons.indexOf(coupon);
if (index != -1) {
$scope.coupons.splice(index, 1);
}
}
下面是一个工作Plunker:<一href=\"http://plnkr.co/edit/b0b2cYGsM5wtw8hIrQB5?p=$p$pview\">http://plnkr.co/edit/b0b2cYGsM5wtw8hIrQB5?p=$p$pview
Here is a working Plunker: http://plnkr.co/edit/b0b2cYGsM5wtw8hIrQB5?p=preview
这篇关于从列表中删除项过滤之后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!