我是Ember.js和Firebase的新手,我设法添加了一个帖子并将其显示在屏幕上,但我仍然坚持能够删除它,是否有人能够帮助我?
////////////////////////////////////////////////////////////
// CONTROLLER
////////////////////////////////////////////////////////////
App.PostsController = Ember.ArrayController.extend({
init: function() {
this.set('post', Ember.Object.create());
},
sortProperties: ['timestamp'],
sortAscending: false, // sorts post by timestamp
actions: {
publishPost: function() {
var newPost = this.store.createRecord('post', {
title: this.get('post.title'),
body: this.get('post.body'),
timestamp: new Date()
});
newPost.save();
},
removePost: function(post) {
var post = this.get('post');
Promise.cast(post.get('post.title')).then(function(posts) {
posts.removeObject(post);
post.destroyRecord();
post.save();
});
}
}
});
////////////////////////////////////////////////////////////
// POSTS
////////////////////////////////////////////////////////////
App.PostsRoute = Ember.Route.extend({
model: function() {
return this.store.findAll('post');
}
});
答案 0 :(得分:1)
我已设法修复下面的更新代码:
removePost: function(the_id)
{
console.log("Look, the record class is actually a promise! :D");
console.log(this.get('store').find('post', the_id));
console.log(this.get('store').find('post', the_id).toString());
this.get('store').find('post', the_id).then(function(rec) {
rec.destroyRecord();
});
}
我没有在索引文件中传递id,这不允许我删除帖子。重写removePost
函数也有帮助。