Restangular - 如何使用GET方法访问此API?

Alw*_*ner 2 angularjs restangular

如何使用以下签名对REST API进行GET调用:

http://www.example.com/hierarchies/nodes/1005/parents
Run Code Online (Sandbox Code Playgroud)

我试图像这样调用API:

var service = Restangular.all('hierarchies');

return service.one('nodes', id).all('parents').get();
Run Code Online (Sandbox Code Playgroud)

但它会引发以下错误:

TypeError: Cannot read property 'toString' of undefined
Run Code Online (Sandbox Code Playgroud)

API调用(如果成功)将以嵌套格式响应,如下所示:

{
    name: "",
    children: [
        {
            name: "",
            children: [
                {
                    name: "",
                    children: [
                        ..
                    ]
                }
            ]
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

提前致谢!

Dav*_*nce 13

我认为如果您使用all构建器的最后一部分,则需要一个列表,您应该使用getList而不是get.但是,您期望的对象看起来不像列表,因此您可以将构建器的最后一部分更改为仅使用one第二个参数,然后使用单个对象作为响应.

service.one('nodes', 5).one('parents').get().then(function(response) {
});
Run Code Online (Sandbox Code Playgroud)