我正在运行这段代码。人集合包含 20 个人,每个人都有包含 6 个朋友的朋友列表字段。写在下面的查询不返回任何数据。但如果您删除查询,则返回 20 人。我怀疑下面的代码是对还是错。
Restangular.one('people',JSON.parse(user_id)).get().then(function(user) {
$scope.user = user;
$scope.infinitePosts = new InfinitePosts(user);
if (user.friends.length !== 0) {
console.log($scope.user.friends)
Restangular.all('people').getList({
where: {
"_id": {
"$in": $scope.user.friends
}
}
}).then(function(friend) {
console.log("------------------")
console.log(friend)
$scope.friends = friend;
});
下面的总代码。
angular.module('weberApp')
.controller('MainCtrl', function($scope, $auth, Restangular, InfinitePosts, $alert, $http, CurrentUser, UserService) {
$scope.UserService = UserService;
$http.get('/api/me', {
headers: {
'Content-Type': 'application/json',
'Authorization': $auth.getToken()
}
}).success(function(user_id) {
Restangular.one('people',JSON.parse(user_id)).get().then(function(user) {
$scope.user = user;
$scope.infinitePosts = new InfinitePosts(user);
if (user.friends.length !== 0) {
console.log($scope.user.friends)
Restangular.all('people').getList({
where: {
"_id": {
"$in": $scope.user.friends
}
}
}).then(function(friend) {
console.log("------------------")
console.log(friend)
$scope.friends = friend;
});
}
$scope.submit_post = function() {
$scope.infinitePosts.addPost($scope.new_post);
$scope.new_post = '';
};
});
});
});