Is there a shorter more elegant way to keep context within BackboneJS view?
this.$el.find(this.itemViewContainer).sortable("destroy").sortable({
connectWith:'.tasks',
delay:140,
revert:200,
items:'li:not(.locked)',
placeholder:'ui-state-highlight',
start:_.bind(function (event, ui){this._sortStart(event, ui);}, this),
receive:_.bind(function (event, ui){this._sortReceive(event, ui);}, this),
stop:_.bind(function (event, ui){this._sortStop(event, ui);}, this)
});
I am reffering to the:
- start event
- receive even
- stop event
it is important that: this, event and ui will be passed to the inner view event.
You can use _.bindAll to lock this to the view in your callbacks:
and you could use it like this
http://jsfiddle.net/nikoshr/wAAZ5/