Datatableを含むコンポーネントがあり、このコンポーネントはコントローラに 'deleteItem'アクションを送信して、そのIDで特定のアイテムを削除します。Ember.js:削除後にデータテーブルコンポーネントから行を削除する
問題は、ストアからアイテムを削除するとビューが更新されないため、削除後にデータテーブルを更新して更新したデータを表示するにはどうすればいいですか?
Controller.js
deleteItem(id){
var store = this.get("store");
store.findRecord('foo', id, {backgroundReload: false}).then(function(foo){
foo.deleteRecord();
foo.save().then(
() => {
console.log(`Done !`);
},
(err) => {
console.log(err);
})}
// fooの-component.hbs
{{yield}}
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>Title</th>
<th>Decription</th>
<th>Category</th>
</tr>
</thead>
<tbody>
{{#each model as |item|}}
<tr>
<td>{{item.title}}</td>
<td>{{item.description}}</td>
<td>{{item.category}}</td>
</tr>
{{/each}}
</tbody>
</table>
//foo-component.js
import Ember from 'ember';
export default Ember.Component.extend({
didInsertElement() {
this.$('table').DataTable({
dom: '<"datatable-header"fl><"datatable-scroll"t><"datatable-footer"ip>',
language: {
search: '<span>Filter:</span> _INPUT_',
lengthMenu: '<span>Show:</span> _MENU_',
manualRowMove: true,
paginate: {
'first': 'First',
'last': 'Last',
'next': '→',
'previous': '←'
}
}
});
this.$('select').select2({
minimumResultsForSearch: Infinity,
width: 'auto'
});
},
actions: {
deleteItem: function(id) {
this.sendAction("deleteItem", id);
}
}
});
あなたのdatatableはどこですか? –
私の投稿の更新を確認してください。 –
わかりません。このように一度だけチェックしてください。 DataTable({...このmyDataTable.ajax.reload();のような行呼び出しを削除した後 –