1

我已经在解析中创建了一个名为 user 的表,并且有一个关系字段 friends 指向同一个表 user。现在我已经通过骨干网获取了用户集合,我得到了一个用户。我怎样才能得到列表包含在字段朋友中的对象?我尝试过 get 方法主干,但它返回一个像这样的对象:Object {__type: "Relation", className: "_User"}。

 var cur_user = Parse.User.current().id;
   var self = this;
   Models.utenti = new Usercollection();
   Models.utenti.fetch({
       success: function (object) {
           var cur_user = Parse.User.current().id;
          // So this gives u a user Model
           var user = Models.utenti.get(cur_user);
           // Lets say the friends list is not a Collection yet
           // Assuming it's just an object
           var friends = user.get("friends"));
          // Create a Friends Collection
          var Collections.friends = New FriendCollection(friends);
           var view = new FriendsView({
               collection: Collections.friends
           });
           self.changePage(view);

       },
       error: function (amici, error) {
           console.log("don t work");
       }
4

1 回答 1

0

您首先不需要使用对象..可以直接使用集合,它是用户的模型集合。

所以我是这样写的,假设有一个朋友收藏

 var friends = user.get("friends"));
  // Create a Friends Collection
   var Collections.friends = New FriendCollection(friends);
   var view = new FriendsView({
       collection: Collections.friends
   });

但是如果朋友也是一个用户列表,那么你可以new UserCollection从朋友对象创建一个然后将它传递给视图

var friends = user.get("friends"));
// Create a Friends Collection
var Collections.friends = New UserCollection(friends);
var view = new FriendsView({
     collection: Collections.friends
 });

var cur_user = Parse.User.current().id;
   var self = this;
   Models.utenti = new Usercollection();
   Models.utenti.fetch({
       success: function (object) {
           var cur_user = Parse.User.current().id;
          // So this gives u a user Model
           var user = Models.utenti.get(cur_user);
           // Lets say the friends list is not a Collection yet
           // Assuming it's just an object
           var friends = user.get("friends"));
          // Create a Friends Collection
           var Collections.friends = New FriendCollection(friends);
           var view = new FriendsView({
               collection: Collections.friends
           });
           self.changePage(view);

       },
       error: function (amici, error) {
           console.log("don t work");
       }
于 2013-07-31T21:00:52.607 回答