【问题标题】:How do I delete a post from Firebase using emberfire如何使用 emberfire 从 Firebase 中删除帖子
【发布时间】:2016-04-06 19:15:38
【问题描述】:

我是 Ember.js 和 Firebase 的新手,我设法添加了一个帖子并将其显示在屏幕上,但我无法删除它,有人能帮我吗?

p>
  ////////////////////////////////////////////////////////////
  // 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');
  }
  });

【问题讨论】:

  • 请更具体一点:到底出了什么问题?
  • 代码中的 removePost 函数不起作用,我不知道为什么?我使用 firebase 作为我的数据库。
  • “不工作”含糊不清 - 你有错误吗?您是否尝试过在保存时使用.then() 以查看它是否被拒绝?
  • 哦,欢迎来到 StackOverflow!最好的问题与您的代码一起具有预期和实际结果。
  • 啊哈,我已经设法修复它下面的更新代码 - removePost: function(the_id){ console.log("看,记录类实际上是一个承诺!: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 函数也有帮助。谢谢:)

标签: ember.js firebase emberfire


【解决方案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 函数也有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多