Restangular - 如何达到预定可使用GET方法此API? [英] Restangular - How do I reach this API using GET method?
问题描述
我如何做一个GET调用一个REST API与下面的签名:
How do I make a GET call to a REST API with the below signature:
http://www.example.com/hierarchies/nodes/1005/parents
我试图调用API,像这样:
I am trying to call the API like so:
var service = Restangular.all('hierarchies');
return service.one('nodes', id).all('parents').get();
但它引发以下错误:
But it throws the following error:
TypeError: Cannot read property 'toString' of undefined
API调用(如果成功的话)将在下面的嵌套形式作出回应:
The API call(if successful) would respond in a nested format as below:
{
name: "",
children: [
{
name: "",
children: [
{
name: "",
children: [
..
]
}
]
}
]
}
在此先感谢!
推荐答案
我想,如果你使用所有
作为建设者的最后部分,名单预计和你应该使用的GetList
而不是 GET
。然而,你所期望的目标看起来并不像一个列表,所以你可以改变你的建设者只使用最后一部分有一个
没有第二个参数,然后一个单独的对象为响应将可以预期的。
I think if you use all
as the last part of the builder, a list is expected and you should use getList
instead of get
. However the object you are expecting does not look like a list, so you could change the last part of your builder to just use one
without the second parameter and then a single object as the response will be expected.
service.one('nodes', 5).one('parents').get().then(function(response) {
});
这篇关于Restangular - 如何达到预定可使用GET方法此API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!