我已经在解析中创建了一个名为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");
}
答案 0 :(得分:0)
您无需首先使用该对象。可以直接使用该集合,该集合是用户的模型集合。
所以我假设有一个朋友集合
就这样写了 var friends = user.get("friends"));
// Create a Friends Collection
var Collections.friends = New FriendCollection(friends);
var view = new FriendsView({
collection: Collections.friends
});
但如果朋友也是一个用户列表,那么你可以从friends对象创建一个new UserCollection
,然后将其传递给View
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");
}