2013-07-31 115 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」} –