如何删除Emberfire的聊天消息?

时间:2015-05-31 02:17:08

标签: ember.js firebase handlebars.js emberfire

我已经创建了一个将消息添加到我的firebase的操作,但似乎无法弄清楚如何删除特定的消息。到目前为止,这是我的新消息控制器:

import Ember from 'ember';

export default Ember.Controller.extend({
//define actions here
actions: {
    addMessage: function() {
        //createRecord creates new instance of message model
        var newMessage = this.store.createRecord('message', {
            //this gets the info from the form fields with this value
            name: this.get('name'),
            body: this.get('body')
        });
        //this saves the data to store and firebase
        newMessage.save();
        //this resets the fields to be blank again
        this.setProperties({
            name: '',
            body: ''
        });
    }
  }
});

这是我的消息控制器,带有删除操作

import Ember from 'ember';

export default Ember.Controller.extend({
actions: {
    deleteMessage: function(id) {
        var msg = this.store.find('message', id, {
            //this gets the info from the form fields with this value
            name: this.get('name'),
            body: this.get('body')
        });
        //this deletes the data to store and firebase
        msg.remove();
    }
}
});

这是我的模板

<div class="new-msg-link">
    {{#link-to 'messages.new'}}Add New Message{{/link-to}}
</div>

{{outlet}}

{{#each message in model}}
    <div class="each-msg">
        {{message.name}}: {{message.body}}
        <button {{action 'deleteMessage'}}>Delete</button>
    </div>
{{/each}}

我不确定如何在我的操作中正确传递id参数以及如何正确地从firebase获取它。任何建议都会很棒!感谢

0 个答案:

没有答案