在我看来,使用 Ember.CollectionView 可以解决这个问题。所以我试了一下。它似乎工作:http: //jsfiddle.net/8ahjd/
车把:
<script type="text/x-handlebars">
{{view App.JQuerySortableView content=model}}
<a {{action removeItem}}>Remove Second Item</a>
</script>
<script type="text/x-handlebars" data-template-name='jquery-sortable-item'>
{{view.content.title}}
</script>
javascript:
App = Ember.Application.create();
App.ApplicationController = Ember.ArrayController.extend({
removeItem: function() {
this.removeAt(1);
}
});
App.ApplicationRoute = Ember.Route.extend({
model: function() {
return [
{id: 1, title:'Test 1'},
{id: 2, title:'Test 2'},
{id: 3, title:'Test 3'}
];
}
});
App.JQuerySortableItemView = Ember.View.extend({
templateName: 'jquery-sortable-item'
});
App.JQuerySortableView = Ember.CollectionView.extend({
tagName: 'ul',
itemViewClass: App.JQuerySortableItemView,
didInsertElement: function(){
this._super();
this.$().sortable().disableSelection();
}
});
</p>