2013-11-21 50 views
0

我得到以下錯誤,當我排序/重新排列div QUICKLYjquery排序用戶界面異常

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

JQuery的UI是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(); 

每當我得到上面的錯誤,這是控制檯的螢火蟲打印什麼:

​​

我猜一旦停止功能被執行,異常或上述錯誤就會發生(因爲我看不到調試語句Inside Stop Function)。

嘗試了幾件事情,如延遲處決。但它沒有奏效。 任何幫助表示讚賞。

UPD: 請注意,以下是在成功的情況下控制檯輸出:

################################################################## 
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 

回答

0

您需要大約ui.placeholder報價爲$('ui.placeholder')