jquery可排序ui异常

jquery sortable ui exceptions

本文关键字:异常 ui 排序 jquery      更新时间:2023-09-26

当我快速排序/重新排列div时,出现以下错误。

TypeError: this.placeholder[0].parentNode is null

JQueryUI是API,我正在使用它:http://jqueryui.com/sortable/

$("#contents").sortable({
    beforeStop: function (event, ui) {
        console.log("BeforeStop Fn Invoked:Parent Node Val:  " + $(ui.placeholder).parent()[0]);
        if (typeof ($(ui.placeholder).parent()[0]) === 'undefined') {
            console.log("If condition passed: " + ($(ui.placeholder).parent()[0]));
            $("#contents").sortable('cancel');
        }
        console.log("BeforeStop Fn Terminates");
    },
    stop: function (event, ui) {
        console.log("Inside Stop Function");
        var op = $(this).sortable('toArray');
        for (i = 0; i < result.length; i++) {
            result[i] = result[i].replace('-sn', '');
        }
        var contents_identifier = JSON.stringify(op);
        $.post(baseurl + 'index.php', {
            para1: contents_identifier
        },
        function (data) {
            fill_content_table();
        });
        console.log("Stop Fun Terminated'n");
    }
}).disableSelection();

每当我出现上述错误时,这就是Firebug控制台打印的内容:

##################################################################
BeforeStop Fn Invoked: Parent Node Val:  undefined
If condition passed: undefined
BeforeStop Fn Terminates
TypeError: this.placeholder[0].parentNode is null

我想一旦执行停止函数,就会出现异常或以上错误(因为我看不到调试语句Inside stop function)。

尝试了一些事情,比如推迟处决。但没有用。感谢您的帮助。

UPD:请注意,以下是SUCCESS情况下的控制台输出:

##################################################################
BeforeStop Fn Invoked: Parent Node Val:  [object HTMLDivElement]
BeforeStop Fn Terminates
Inside Stop Function
POST https://www. 200 OK 730ms  
Stop Fun Terminated
####################################################
POST https:www.........200 OK 734ms

您需要在ui.placeholder周围加引号作为$('ui.placeholder')