2013-07-31 112 views
1

我已经创建了一个称为用户的解析表中的表,并有一个关系字段的朋友指向同一个表user.Now我已经取得骨干收集的用户和我得到一个单一的用户。我怎样才能得到包含到字段朋友对象的列表?我已经通过get方法骨干尝试过,但它返回一个像这样的对象:Object {__type:“Relation”,className:“_User”}。在parse.com关系领域的Retriew对象

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"); 
     } 
+0

你到底是在响应返回什么时候收集获取..我希望它是'Models.utenti'权利的更新列表? –

+0

是的,它返回更新的集合 –

+0

那么你为什么要在这里使用'对象',你可以直接访问集合..而恶魔列表是一个收集权..为什么你想要通过作为模型..将它作为集合传递 –

回答

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"); 
     } 
+0

也许你不明白问题 –

+0

@StefanoMaglione ..如果这不是这种情况,你可以更清楚地解释你的问题 –

+0

朋友是用户的属性。在parse.com此属性具有关系类型指向表user.o这个属性必须是一个对象列表,但console.log(朋友)显示:Object {__type:“Relation”,className:“_User”} –