DeleteRecord does not update ArrayController when the model is filtered

I am using a simple Ember.ArrayController in an application with ember-data (the latter), ember rc6 and a REST control controller.

I have deletion actions next to each item in the list displayed by the array controller. When an item is deleted, the correct REST API call is made and it is properly removed from the database. The server responds with the correct answer 204 .

Here is my router setup, pay attention to the search filter used

 App.CategoriesIndexRoute = Ember.Route.extend({ setupController : function(controller, model) { this._super(controller, model); controller.set("content", App.Category.find({ "parent": null, })); } }); 

If I remove the search filter and load all categories, everything works fine (the item is automatically removed from the list immediately after committing). However, when I add a filter only to display categories that do not have a parent, the list is not updated when the item is deleted. If I move to another section and return, the list will be reloaded and the category will disappear.

Here is the deleteCategory method in the ArrayController :

 deleteCategory: function(category) { var transaction = this.get("store").transaction(); transaction.add(category); category.deleteRecord(); transaction.commit(); } 

Is this an ember-data or emberjs ? If not, what am I doing wrong here? If this is an error, is there a way to force reload the contents of the ArrayController after deleting the item? Alternatively, is it possible to manually remove a category from ArrayController?

UPDATE 1:

I managed to force update the contents of the array controller by setting its contents:

 category.one("didDelete", this, function() { this.set("content", App.Category.find({ parent: parent_category })); }); 

UPDATE 2:

This is how I show the list of elements in the template:

 {{#each category in controller.content }} <tr> <td><a {{ action "detailCategory" category }}>{{ category.name }}</a></td> <td><a {{ action "deleteCategory" category }}>Delete</a></td> </tr> {{/each}} 

Thanks!

+6
source share
1 answer

This is no longer a way to do things in Ember Data. You cannot use transactions anymore, as seen in the transition document: https://github.com/emberjs/data/blob/master/TRANSITION.md

0
source

Source: https://habr.com/ru/post/948534/


All Articles