Ric*_*ges 2 javascript jquery jquery-ui
我正在尝试销毁 jQuery UI 的可拖动实例,但收到“无法调用方法”错误。
我的代码
$('table.paper tr').draggable({
helper: 'clone',
create: function(event, ui) {
$('body').on('click', '[data-action="edit-ingredients"]', function(event) {
event.preventDefault();
$('table.paper').draggable('destroy');
});
},
start: function(event, ui) {
c.tr = this;
c.helper = ui.helper
$(this).hide();
},
drag: function(event, ui) {
var collides = $('table.paper').overlaps($(c.helper));
if (collides.hits.length) {
$(c.helper).removeClass('delete');
} else {
$(c.helper).addClass('delete');
}
}
});
Run Code Online (Sandbox Code Playgroud)
错误
Error: cannot call methods on draggable prior to initialization; attempted to call method 'destroy'
http://code.jquery.com/jquery-1.11.0.min.js
Line 2
在“逻辑说话”中,这个错误告诉我我的代码流不正确,因为当我尝试销毁它时 jQuery UI 的可拖动对象未启动 - 但是,正如您所看到的,我正在可拖动对象的 ' 中创建事件侦听器创建'事件。