2011-07-07 41 views
5

我有一個通過ajax填充的列表。這個列表我可以通過ajax添加和刪除項目並對它們進行排序。我有兩個問題。通過ajax更新內容時的可排序功能

第一個是在這裏,它仍然沒有解決:https://stackoverflow.com/questions/6370213/jquery-dynamic-dragn-drop-doesnt-update-order

第二個更糟糕的是(排序列表來自數據庫將不會更新,直到我刷新項目數後)。當我通過ajax更新列表中的內容(比如添加一個新項目)後,排序函數將停止工作,直到我重新加載頁面。看起來.live不會與排序工作,我對這個問題不瞭解。我會添加一些我的代碼:

我的目錄是這樣的:

<ul id="listaruta"> 
    <li> ... </li> 
</ul> 

我分揀物品腳本:

$(function() { 
    $("ul#listaruta").sortable({ 
     opacity: 0.6, 
     cursor: 'move', 
     update: function() { 
      var order = $(this).sortable("serialize") + '&action=updateRecordsListings'; 
      $.post("/plugins/drag/updateDB.php", order);                
    }         
    }); 
}); 

我用這對排序功能:http://www.webresourcesdepot.com/wp-content/uploads/file/jquerydragdrop/

回答

7

搜索了很多後,我發現這是我的回答:jQuery live and sortable

這是我添加到我的代碼,使其工作:

$(document).ajaxSuccess(function() { 

    $("ul#listaruta").sortable({ 
     opacity: 0.6, 
     cursor: 'move', 
     update: function() { 
      var order = $(this).sortable("serialize") + '&action=updateRecordsListings'; 
      $.post("/plugins/drag/updateDB.php", order); 
     } 
    }); 
}); 
+0

謝謝!這嚇壞了我! :d – freeworlder