JQuery UI sortable and backbone.js

I have a backbone.js project that I have been working on, and I have a setting so that I can drag and drop rows (which are backbone.js models) and using the jQuery UI update event, which I can have my models re-evaluate the order, and things are good. I was wondering if anyone has a new cleaner way to do this. I have added the code below.

$( ".section" ).sortable({items: 'tr', update: function() { console.log("Event Fire!"); secv.mySort(); }}); 

secv is my view for a model that contains a table. The mySort function passes and calculates the order of the elements and makes the necessary update.

+7
source share
1 answer

I assume that you are setting the collection property in the view, possibly in the initialize method. In the same method, you must bind the view method to the "change" or "refresh" event of the collection. This method simply redraws the sorted collection; sorting the collection before then, if necessary.

In theory, your model would potentially update itself with its new position, and if the collection had the function of a comparator, the collection would automatically be applied by itself. If so, binding to the 'refresh' event of the collection will call the aforementioned method, which should only redisplay part of the collection in the view.

+1
source

All Articles