admin管理员组文章数量:1332382
I am trying to get some data from a REST api using mgonto's Restangular.
// Restangular returns promises
Restangular.all('users').getList() // GET: /users
.then(function(users) {
// returns a list of users
$scope.user = users[0]; // first Restangular obj in list: { id: 123 }
})
// Later in the code...
// Restangular objects are self-aware and know how to make their own RESTful requests
$scope.user.getList('cars'); // GET: /users/123/cars
That's fine, and this works, but all the results returned in the promises callbacks have some methods and properties added by Restangular (this is how you can do .getList("cars") on a user).
What I want is to retrieve only the user's data (name, id...) without all the Restangular methods. Just a plain JS object.
I couldn't find any way to do this in the docs. Everytime I use a method on a returned user it always returns a wrapped object with the Restangular methods.
I am trying to get some data from a REST api using mgonto's Restangular.
// Restangular returns promises
Restangular.all('users').getList() // GET: /users
.then(function(users) {
// returns a list of users
$scope.user = users[0]; // first Restangular obj in list: { id: 123 }
})
// Later in the code...
// Restangular objects are self-aware and know how to make their own RESTful requests
$scope.user.getList('cars'); // GET: /users/123/cars
That's fine, and this works, but all the results returned in the promises callbacks have some methods and properties added by Restangular (this is how you can do .getList("cars") on a user).
What I want is to retrieve only the user's data (name, id...) without all the Restangular methods. Just a plain JS object.
I couldn't find any way to do this in the docs. Everytime I use a method on a returned user it always returns a wrapped object with the Restangular methods.
Share asked Aug 27, 2015 at 15:49 RayjaxRayjax 7,78413 gold badges57 silver badges85 bronze badges1 Answer
Reset to default 8I guess you are looking for 'plain()' (alias for Restangular.stripRestangular(elem)).
plain(): Returns the plain element received from the server without any of the enhanced methods from Restangular. It's an alias to calling Restangular.stripRestangular(elem)
It strips all the restangular methods and returns the plain object which is returned by the server.
For more information please refer to the following link :
https://github./mgonto/restangular#element-methods
The following fiddle might help :
Fiddle ::
http://plnkr.co/edit/oMFnYM4HkaFK3biscpTo?p=preview
本文标签: javascriptRestangularHow to get the request39s plain results (not wrapped)Stack Overflow
版权声明:本文标题:javascript - Restangular - How to get the request's plain results (not wrapped) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742294012a2448355.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论