jQueryUI draggable + sortable bug(无法读取undefined的属性’options’)

我的问题似乎与这个问题相似:

从可排序列表拖动到拖放插件

但由于没有给出那个答案,我想知道是否有人能够/能够和我一起解决这个问题。 我遇到的问题是我创建了一个可拖动的div并将其附加到一个可以排序的div中。 当我指定任何这样的参数时:

$(el).sortable({ ... arguments ... }); 

当元素被删除时,它会导致错误,如果留空,它会奇怪地工作正常并且没有问题。 该错误还会阻止可拖动元素触发任何函数。

 Uncaught TypeError: Cannot read property 'options' of undefined jquery-ui-1.10.3.custom.js:2204 $.ui.plugin.add.stop jquery-ui-1.10.3.custom.js:2204 $.extend.plugin.call jquery-ui-1.10.3.custom.js:284 $.widget._trigger jquery-ui-1.10.3.custom.js:2017 (anonymous function) jquery-ui-1.10.3.custom.js:401 $.widget._mouseStop jquery-ui-1.10.3.custom.js:1702 (anonymous function) jquery-ui-1.10.3.custom.js:401 $.widget._mouseUp jquery-ui-1.10.3.custom.js:957 (anonymous function) jquery-ui-1.10.3.custom.js:401 $.widget._mouseUp jquery-ui-1.10.3.custom.js:1721 (anonymous function) jquery-ui-1.10.3.custom.js:401 $.widget._mouseDown._mouseUpDelegate jquery-ui-1.10.3.custom.js:913 jQuery.event.dispatch jquery-1.10.2.js:5095 jQuery.event.add.elemData.handle jquery-1.10.2.js:4766 

这是出错的代码:

 $.ui.plugin.add("draggable", "cursor", { start: function() { var t = $("body"), o = $(this).data("ui-draggable").options; if (t.css("cursor")) { o._cursor = t.css("cursor"); } t.css("cursor", o.cursor); }, stop: function() { var o = $(this).data("ui-draggable").options; if (o._cursor) { $("body").css("cursor", o._cursor); } } }); 

var o = $(this).data("ui-draggable").options; $(this).data()仅包含:Object {id:“c17”}

示例代码:

 $('.draggable').draggable({ connectToSortable: '.sortable', drop: function(){ console.log('Element dropped'); } }); $('.sortable').sortable({ update: function(){ console.log('sortable updated'); } }); 

JSBin示例: http ://jsbin.com/eHUKuCoL/9/edit?html,js,output。希望有人能够告诉我问题是什么以及解决问题的方法是什么。

根据文档Jquery UI Draggable Documentation ,您需要将helper参数设置为“clone”,以使connectWithSortablefunction完美地工作。

一旦我这样做,它就停止了抛出错误。

更新了JSBin

另外一个注释,draggable在其文档中没有’drop’方法,所以你可能必须包含droppable插件,如果这就是你想要的。

最后,如果你必须使用clone作为帮助方法,你可能需要添加一些css以使其运行更顺畅。

干杯。

在使用Meteor构建高度动态的应用程序时,我也遇到了这个问题。 事实certificate,如果您删除原始拖动项(或没有克隆它),您将收到此错误。 这在不同版本的jQuery中多次出现,但现在最终在v1.11.0中得到修复:

http://bugs.jqueryui.com/ticket/6889