简体   繁体   English

矩形-删除不带ID的请求

[英]Restangular - Delete Request Without ID

I am using the rectangular library with angular.js. 我正在使用与angular.js的矩形库。 I currently have a service called me that represents the currently authenticated user. 我目前有一个名为我的服务,代表当前经过身份验证的用户。

 services/me

I also have a service called desk that represents that user's current location by returning a single desk object. 我还有一个称为Desk的服务,该服务通过返回单个desk对象来表示该用户的当前位置。

 services/me/desk

I want to be able to delete the desk to remove a person's current location, by calling a delete request on it. 我希望能够通过调用办公桌上的删除请求来删除办公桌以删除一个人的当前位置。 However, whenever I do, restangular adds the id of the desk as a parameter making the url: 但是,每当我这样做时,restangular都会将桌子的id作为参数添加到网址中:

 services/me/desk/:id

I can't for the life of me figure out how to get it to send a delete request without automatically appending the ID. 我一辈子都无法弄清楚如何在不自动附加ID的情况下发送删除请求。 Please let me know if there is a way to do this within the library. 请让我知道图书馆内是否有办法做到这一点。

Thanks! 谢谢!

I assume because the object you are removing was retrieved via Restangular that it's being smart because you have a property called id. 我假设因为要删除的对象是通过Restangular检索的,所以它很聪明,因为您有一个名为id的属性。 Try one of the following. 请尝试以下方法之一。 Both should work. 两者都应该起作用。 They're not connected directly with the object you received: 它们没有直接与您收到的对象连接:

1. 1。

Restangular.one('services/me/desk').remove().then(
function (response) {
    // success
},
function (response) {
    // error
});

2. 2。

Restangular.customDELETE("services/me/desk", {}, { 'Content-Type': 'application/json' }).then(
function (response) {
    // success
},
function (response) {
    // error
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM