vendredi 20 mars 2015

Saving order update on server

the interface of an app allows the items to be ordered by drag and drop. When an item is rearranged, the order property of all the items will be updated to match its new order. I use Sortable.js for this functionality, so far everything is fine.


Now I want to save these new ordered elements to the server. For example in my route I fetch all favorites:



model: ->
return this.store.find('favorite')


After reordering some of my favorites, I do this.get('model').save(). This way all my favorite records are seperately saved to the server with a PUT request per favorite PUT > /api/favorites/2.


This works fine when I don't have too many favorites, but this approach feels wrong when e.g I have 50 favorites and on every reorder I will send 50 PUT requests.


What would be a better approach for persisting the order of different records to the server?





Aucun commentaire:

Enregistrer un commentaire