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 から正しく取得する方法がわかりません。どんな提案も素晴らしいでしょう!ありがとう