【发布时间】:2013-07-06 04:31:04
【问题描述】:
我是backbonejs 的新手,我正在做一些项目,包括获取和显示朋友列表。对于这个项目,我使用 parse.com 作为数据库。但我现在有货了。
例如:我在用户和朋友模型中有以下数据。
var user = [
{
id: 'x1',
firstname: 'Ashik',
lastname: 'shrestha',
phone: '12321321',
mobile: '123213',
email: 'xyz@gmail.com'
},
{
id: 'x2',
firstname: 'rokesh',
lastname: 'shrestha',
phone: '12321321',
mobile: '123213',
email: 'rokesh@gmail.com'
},
];
var friends = [
{
user_id: 'x1',
user_friend_id: 'x2'
},
{
user_id: 'x1',
user_friend_id: 'x4'
},
{
user_id: 'x1',
user_friend_id: 'x10'
},
{
user_id: 'x2',
user_friend_id: 'x25'
}
];
// 集合
var userCollection = Backbone.collection.extend({
model: user
});
var friendListCollection = Backbone.collection.extend({
model: friends
});
var friends = new friendListCollection();
现在我想要什么?
当我获取好友集合对象时,我想获取用户的好友列表及其详细信息。
例子::
friends.fetch({
success: function(ob){
var ob =ob.toJSON();
// i want ob to be like
[
{
id: 'x2',
firstname: 'rokesh',
lastname: 'shrestha',
phone: '12321321',
mobile: '123213',
email: 'rokesh@gmail.com'
},
{
id: 'x4',
firstname: 'rokesh',
lastname: 'shrestha',
phone: '12321321',
mobile: '123213',
email: 'rokesh@gmail.com'
},
{
id: 'xx10',
firstname: 'rokesh',
lastname: 'shrestha',
phone: '12321321',
mobile: '123213',
email: 'rokesh@gmail.com'
},
]
}
});
我应该创建新的集合来关联它们还是有其他方法可以做到这一点??
提前致谢!
【问题讨论】:
标签: backbone.js backbone-relational backbone.js-collections backbone-model