Restangular delete from list after remove() not wo

2019-09-01 15:55发布

i've been trying to work with Restangular, but there are some issues i'm running into. i'm not sure if its the implementation of Restangular, or my lack of understanding, but i can't seem to delete anything from a returned getList on the Restangular object.

I was looking at this post and trying to implement something very similar to this:

AngularJS (Restangular CRUD , Simplify / DRY Controllers?)

But no matter what i do, i can't delete or remove items from the list. adding or pushing is fine. but not deleting. I went back and did it exactly like the docs said. here is my example delete function:

$scope.deletePost = function(item){
item.remove().then(function(results){
$scope.posts = _.without($scope.posts, item);
});

};

I've tried just about everything, so i'm hoping that somebody here can shed some light on implementing Restangular delete. it Does, in fact, remove the item from the database, howver, the problem i'm having is then updating the list on the client side without doing a full getList() call. i've tried the _.without and splice as well. nothing seems to work.

thanks.

1条回答
老娘就宠你
2楼-- · 2019-09-01 16:30

I had that problem too.

this worked on my code:

$scope.deletePost = function(item){
    item.remove().then(function(results){
        $scope.posts.$object.splice($scope.posts.$object.indexOf(item),1);
    });
}
查看更多
登录 后发表回答