我做了这个,它将 ArrayController 的顺序绑定到 View :
Ember.SortableView = Em.CollectionView.extend({
tagName: "ul",
moveItem: function(fromIndex, toIndex){
var items = this.get('content');
var item = items.objectAt(fromIndex);
items.removeAt(fromIndex);
items.insertAt(toIndex, item);
},
didInsertElement: function() {
var view = this;
view.$().sortable({
cursor: "move",
start: function(event, ui) {
ui.item.previousIndex = ui.item.index();
},
stop: function(event, ui) {
view.moveItem(ui.item.previousIndex, ui.item.index());
}
});
},
willDestroyElement: function() {
this.$().sortable('destroy');
}
});
像这样使用它:
{{#collection "Ember.SortableView" contentBinding="items"}}
template of an item
{{/collection}}