有没有关于如何使用Ember.js实现拖放的示例?我已经尝试使用jQuery UI,但整合似乎有点复杂.
我看过这个jsFiddle:http://jsfiddle.net/oskbor/Wu2cu/1/,但是在我自己的应用程序中没能成功实现.
使用Ember.js进行相当简单的拖放实现有哪些选择?
解决方法
我看了Remy Sharp的
post,并在Ember.js中实现了一个基本的例子,见
http://jsfiddle.net/pangratz666/DYnNH/.
把手:
<script type="text/x-handlebars" > Drag and drop the green and red Box onto the blue one ... {{view App.Box class="Box green"}} {{view App.Box class="Box red"}} {{view App.DropTarget class="Box blue"}} </script>
JavaScript的:
DragNDrop = Ember.Namespace.create(); DragNDrop.cancel = function(event) { event.preventDefault(); return false; }; DragNDrop.Dragable = Ember.Mixin.create({ attributeBindings: 'draggable',draggable: 'true',dragStart: function(event) { var dataTransfer = event.originalEvent.dataTransfer; dataTransfer.setData('Text',this.get('elementId')); } }); DragNDrop.Droppable = Ember.Mixin.create({ dragEnter: DragNDrop.cancel,dragOver: DragNDrop.cancel,drop: function(event) { var viewId = event.originalEvent.dataTransfer.getData('Text'); Ember.View.views[viewId].destroy(); event.preventDefault(); return false; } }); App.Box = Ember.View.extend(DragNDrop.Dragable); App.DropTarget = Ember.View.extend(DragNDrop.Droppable);