在初始化之前无法在可拖动对象上调用方法
我正在尝试销毁jQuery UI的可拖动实例,但收到无法调用方法"错误.
I'm trying to destroy an instance of jQuery UI's draggable, but I'm receiving a 'cannot call method' error.
我的代码
$('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');
}
}
});
错误 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
The errorError: 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时,它不会启动jQuery UI的可拖动对象-但是,正如您所看到的,我正在其中创建事件监听器可拖动对象的创建"事件.
In 'logic speak', this error is telling me my flow of code isn't correct as jQuery UI's draggable isn't initiated when I attempt to destroy it - however, as you can see I am creating the event listener within the draggable's 'create' event.
您正在使用选择器$('table.paper tr')
实例化可拖动对象,然后使用其他选择器$('table.paper')
销毁可拖动对象,我认为这不是可拖动元素.
you are instantiating a draggable with selector $('table.paper tr')
then destroying a draggable with a different selector $('table.paper')
which i assume is not a draggable element.