Restangular delete from list after remove() not working

旧时模样 提交于 2019-12-12 04:59:11

问题


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:


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);
    });
}


来源:https://stackoverflow.com/questions/23525824/restangular-delete-from-list-after-remove-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!