I still find my way with Backbone, and I always used Prototype instead of jQuery in the past, so please forgive me if I do something stupid.
I am trying to develop an interface containing several connected unordered lists, where each sortable list is represented by a separate base. I use ICanHaz and Mustache templates, but this is not important for my question.
When dragging items between lists, what is the best way for me to automatically update collections (remove the model from one and paste it into another)? I'm currently trying to use the receive and delete methods in jQueryUI Sortable interaction - am I at least on the right lines?
var WS = {}; (function(ns) { ns.Item = Backbone.Model.extend(); ns.Content = Backbone.Collection.extend({ model: ns.Item, url: location.href, initialize: function(el) { this.el = $(el); this.deferred = this.fetch(); }, recalculate: function() { var count = this.length; this.el.next(".subtotal").html(count); }, setOrder: function() { $.ajax({ url: this.url + "/reorder", type: "POST", data: "tasks=" + $(this.el).attr("id") + "&" + this.el.sortable("serialize") }); } }); ns.ContentRow = Backbone.View.extend({ tagName: "li", className: "item", events: { "click .delete": "destroy" }, initialize: function(options) { _.bindAll(this, "render", "destroy"); this.model.bind("change", this.render); this.model.view = this; }, render: function() { var row = ich.item(this.model.toJSON()); $(this.el).html(row); return this; }, destroy: function() { if (confirm("Really delete?")) { this.model.destroy({ success: function(model, response) { $(model.view.el).remove(); }, error: function(model, response) { console.log(response); } }); } } }); ns.ListView = Backbone.View.extend({ initialize: function(collection) { this.el = collection.el; this.collection = collection; this.collection.bind("add", this.addOne, this); _.bindAll(this, "addOne"); this.el.sortable({ axis: "y", connectWith: ".tasks", receive: _.bind(function(event, ui) {
source share