我的问题似乎类似于这个问题:
从可排序列表拖动到拖放插件 https://stackoverflow.com/questions/17928139/dragging-from-a-sortable-list-to-a-drag-and-drop-plugin
但由于没有给出答案,我想知道是否有人可以/能够和我一起解决这个问题。我遇到的问题是我创建了一个可拖动的 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;
The $(this).data()
仅包含:对象 {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,输出 http://jsbin.com/eHUKuCoL/9/edit?html,js,output希望有人能够告诉我问题是什么以及问题的解决方法是什么。