我对整个 Ember 的东西还很陌生,我真的很想获得更多真实场景的示例代码。我看过有关身份验证的 Embercast,这很有帮助,但我正在尝试创建一个应用程序,其中包含各种用户拥有的帖子列表,其他用户可以将其添加到他们的收藏夹中。
当然,这对我目前的水平来说是雄心勃勃的,但我希望这里的某个人能够为我指出一个例子,甚至创造一个例子。我认为这样的东西对其他人来说是一个极好的资源——比 Ember 指南中的 Todo 列表示例更重要,它真的不足以展示我如何创建一个真正的应用程序。我认为,我们需要更多关于身份验证的示例。
到目前为止,这是我的模型和固定装置:
App.User = DS.Model.extend({
name: DS.attr('string'),
email: DS.attr('string'),
posts: DS.hasMany('post'),
favourites: DS.hasMany('favourite')
});
App.User.FIXTURES = [{
id: 1,
name: 'Bob Jones',
email: 'bob@jones.com',
favourites: [2]
}];
App.Post = DS.Model.extend({
date_posted: DS.attr('date'),
title: DS.attr('string'),
description: DS.attr('description'),
comments: DS.hasMany('comment'),
});
App.Post.FIXTURES = [{
id: 1,
date_posted: new Date,
title: 'Red',
description: 'Great colour'
comments: []
}, {
id: 2,
date_posted: new Date,
title: 'Blue',
description: 'Makes me sad',
comments: [1]
}];
App.Comment = DS.Model.extend({
post: DS.belongsTo('post'),
date_posted: DS.attr('date'),
author: DS.attr('string'),
message: DS.attr('string'),
});
App.Comment.FIXTURES = [{
id: 1,
post: [2],
date_posted: new Date,
author: 'Aaron',
message: 'I agree with the description.'
}];
App.Favourite = DS.Model.extend({
user: DS.belongsTo('user'),
post: DS.belongsTo('post')
});
App.Favourite.FIXTURES = [{
user: 1,
post: 2
}];
我觉得这是最简单的部分,我什至不能 100% 确信这些是正确组合在一起的。
感谢您对此的任何指导!