使用Restangular嵌套资源 [英] Nested resources with Restangular
问题描述
我正在使用Restangular.在我的应用程序中,我有两个REST资源,
I am using Restangular. In my application, I have two REST resources,
-
根据ID获取用户/users/123
To get the User based on the ID /users/123
获取用户的好友详细信息users/123/buddies/456
To get the buddy details of the user users/123/buddies/456
下面是我正在使用的代码,
Below is the code I am using,
//get the user
Restangular.one("users", 123).get().then(function(user){
$scope.user = user;
});
矩形调用/users/123.到目前为止一切顺利.
Restangular makes a call to /users/123. So far so good.
//get the buddy
var getBuddy = function(){
$scope.user.one("buddies", "456").get();
}
但是在这里,Restangular调用了/users/buddies/456而不是/users/123/buddies/456.
But here, Restangular makes the call to /users/buddies/456 instead of /users/123/buddies/456.
我已经仔细阅读了提供的示例,但发现不了一个错误.看来我正在监督显而易见的事情,但是这个问题使我感到沮丧的已经超过一天了.有人提示吗?
I have gone through the samples provided and I can't spot a mistake. Looks like I am overseeing the obvious but this issue has been frustrating me for more than a day now. Does anyone have a hint?
谢谢
推荐答案
答案在Restangular中文档
The answer lies in the Restangular documentation
如果您使用的是MongoDB,请记住配置id字段.
If you are using MongoDB, remember to configure the id field.
这篇关于使用Restangular嵌套资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!