【问题标题】:Make Restangular .remove() work with Rails Shallow Routes使 Restangular .remove() 与 Rails 浅层路线一起使用
【发布时间】:2016-02-04 07:16:24
【问题描述】:

说,我有如下嵌套资源,

shallow do
  resources :aalu do
    resources :pyaj
  end
end

使用restangular,我使用以下Restangular 调用获得所需的资源

all_pyaj = Restangular.one('aalu', $stateParams.aaluId).all('pyaj').getList();

pyajall_pyaj 数组的一个元素,我使用 ng-repeat 得到它。

现在,当我想使用 remove() 方法使用 Restangular 删除资源时, pyaj.remove()/aalu/:aalu_id/pyaj/:pyaj_id 进行 DELETE 调用

我希望它对 /pyaj/:pyaj_id 进行 DELETE 调用,并从角度 $scope 中删除资源。

我可以通过以下方式实现,

Restangular.one('pyaj', payj.id).remove().then(
   function (response) { /* Problem: Delete this pyaj from $scope */ }

我可以让 Restangular 对 /pyaj/:pyaj_id 进行 DELETE 调用并从 angular $scope 中删除资源吗?

Restangular 如何处理浅层路线?

【问题讨论】:

    标签: ruby-on-rails angularjs restangular


    【解决方案1】:

    你应该用RestangularProvider.setParentless(['pyaj']); 配置Restangular,告诉它任何pyaj 对象都应该是“浅的”。见https://github.com/mgonto/restangular#setparentless

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-11-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-19
      • 1970-01-01
      • 1970-01-01
      • 2011-10-16
      相关资源
      最近更新 更多