在初始化之前无法在可拖动对象上调用方法 [英] cannot call methods on draggable prior to initialization

查看:95
本文介绍了在初始化之前无法在可拖动对象上调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试销毁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 error
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时,它不会启动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.

这篇关于在初始化之前无法在可拖动对象上调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆