[英]Make Restangular .remove() work with Rails Shallow Routes
Say, I have nested resources as follows, 说,我嵌套了以下资源,
shallow do
resources :aalu do
resources :pyaj
end
end
Using restangular I get the resources as required using the following Restangular
call 使用restangular我通过以下Restangular
调用获得所需的资源
all_pyaj = Restangular.one('aalu', $stateParams.aaluId).all('pyaj').getList();
pyaj
is an element of the all_pyaj
array, I get it using ng-repeat. pyaj
是all_pyaj
数组的元素,我使用ng-repeat来获取。
Now, When I want to remove the resource using Restangular using remove()
method, the pyaj.remove()
makes a DELETE call to /aalu/:aalu_id/pyaj/:pyaj_id
现在,当我想使用remove()
方法使用Restangular删除资源时, pyaj.remove()
对/aalu/:aalu_id/pyaj/:pyaj_id
进行DELETE调用
I want it to make a DELETE call to /pyaj/:pyaj_id
and remove the resrouce form the angular $scope too. 我希望它对/pyaj/:pyaj_id
进行DELETE调用,并从角度$ scope中删除/pyaj/:pyaj_id
。
I can achieve this by the following way, 我可以通过以下方式实现这一目标,
Restangular.one('pyaj', payj.id).remove().then(
function (response) { /* Problem: Delete this pyaj from $scope */ }
Can I make Restangular make a DELETE call to /pyaj/:pyaj_id
and remove the resource form the angular $scope too? 我可以让Restangular对/pyaj/:pyaj_id
pyaj_id进行DELETE调用,也可以从有角度的$ scope中删除资源吗?
How Restangular works with shallow routes? Restangular如何在浅层路线上工作?
You should configure Restangular with RestangularProvider.setParentless(['pyaj']);
您应该使用RestangularProvider.setParentless(['pyaj']);
配置Restangular RestangularProvider.setParentless(['pyaj']);
to tell it that any pyaj
object should be "shallow". 告诉它任何pyaj
对象都应该是“浅”的。 See https://github.com/mgonto/restangular#setparentless . 参见https://github.com/mgonto/restangular#setparentless 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.