Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Authentication 如何创建可以添加到用户收藏夹的帖子列表?_Authentication_Ember.js_Model_Favorite - Fatal编程技术网

Authentication 如何创建可以添加到用户收藏夹的帖子列表?

Authentication 如何创建可以添加到用户收藏夹的帖子列表?,authentication,ember.js,model,favorite,Authentication,Ember.js,Model,Favorite,我对余烬这件事还不太熟悉,我真的很想知道更多真实场景的示例代码。我看过关于身份验证的Embercast,这很有帮助,但我正在尝试创建一个应用程序,其中包含一个由不同用户拥有的帖子列表,其他用户可以将其添加到他们的收藏夹中 当然,这对我目前的水平来说是雄心勃勃的,但我希望这里的人能给我举个例子,甚至创建一个。我认为这样的东西对其他人来说是一个很好的资源——比《灰烬指南》中的Todo列表示例更重要,它实际上还不足以展示我如何创建一个真正的应用程序。我认为,我们需要更多的认证示例 以下是迄今为止我的模

我对余烬这件事还不太熟悉,我真的很想知道更多真实场景的示例代码。我看过关于身份验证的Embercast,这很有帮助,但我正在尝试创建一个应用程序,其中包含一个由不同用户拥有的帖子列表,其他用户可以将其添加到他们的收藏夹中

当然,这对我目前的水平来说是雄心勃勃的,但我希望这里的人能给我举个例子,甚至创建一个。我认为这样的东西对其他人来说是一个很好的资源——比《灰烬指南》中的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%的信心将它们正确地组合在一起


谢谢你的指导

这里有几个问题。首先,您使用的是fixture,所以您应该使用FixtureAdapter。由于您在fixture数据中定义了关系,但数据只有一个id,因此需要将这些关系标记为异步。此外,在您的用户装置中,它有一个最喜爱的id 2,但您最喜爱的装置没有id

App.User = DS.Model.extend({
    name: DS.attr('string'),
    email: DS.attr('string'),
    posts: DS.hasMany('post', {async:true}),
    favourites: DS.hasMany('favourite', {async:true})
});
App.User.FIXTURES = [{
    id: 1,
    name: 'Bob Jones',
    email: 'bob@jones.com',
    favourites: [2],
    // you have no posts defined here??
}];

App.Post = DS.Model.extend({
    date_posted: DS.attr('date'),
    title: DS.attr('string'),
    description: DS.attr('description'),
    comments: DS.hasMany('comment', {async:true}),
});
App.Post.FIXTURES = [{
    id: 1,
    date_posted: new Date,
    title: 'Red',
    description: 'Great colour', // also missing this comma
    comments: []
}, {
    id: 2,
    date_posted: new Date,
    title: 'Blue',
    description: 'Makes me sad',
    comments: [1]
}];

App.Comment = DS.Model.extend({
    post: DS.belongsTo('post', {async:true}),
    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', {async:true}),
    post: DS.belongsTo('post', {async:true})
});
App.Favourite.FIXTURES = [{
    id: 2, // it needs some sort of unique identifier
    user: 1,
    post: 2
}];
此外,您可能需要阅读Ember数据转换文档,这可能有助于解决您的一些问题


下面是我用您的数据制作的一个小示例,

谢谢!我看到我的模型和夹具数据中有一些漏洞,所以这些肯定会让我一路绊倒。我还想知道,我意识到我要求很多,是否有可能装配添加到收藏夹的操作,并让模板反映某些内容是否在收藏夹中?我想这会让我和很多其他人都了解余烬的整个关系。我已经建立了一个博客,但这类事情仍然超出了我的理解,我认为,因为它不仅仅是博客或待办事项列表中的超基本数据关系。就连我的博客也没有关于拥有帖子的用户的概念。