簡體   English   中英

Restangular - 如何使用GET方法訪問此API?

[英]Restangular - How do I reach this API using GET method?

如何使用以下簽名對REST API進行GET調用:

http://www.example.com/hierarchies/nodes/1005/parents

我試圖像這樣調用API:

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

return service.one('nodes', id).all('parents').get();

但它會引發以下錯誤:

TypeError: Cannot read property 'toString' of undefined

API調用(如果成功)將以嵌套格式響應,如下所示:

{
    name: "",
    children: [
        {
            name: "",
            children: [
                {
                    name: "",
                    children: [
                        ..
                    ]
                }
            ]
        }
    ]
}

提前致謝!

我認為如果你使用all作為構建器的最后一部分,則需要一個列表,你應該使用getList而不是get 但是你期望看起來並不像一個清單,這樣你就可以改變你的建設者只使用最后一部分的對象one沒有第二個參數,然后一個對象作為響應將有望。

service.one('nodes', 5).one('parents').get().then(function(response) {
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM