【问题标题】:Sortable function when content is updated via ajax通过 ajax 更新内容时的可排序功能
【发布时间】:2011-07-07 09:22:44
【问题描述】:

我有一个通过 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/

【问题讨论】:

    标签: jquery ajax jquery-ui-sortable


    【解决方案1】:

    在搜索了很多之后,我发现这是我的答案: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);
            }
        });
    });
    

    【讨论】:

    • 谢谢!这把我吓坏了! :D
    猜你喜欢
    • 1970-01-01
    • 2016-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多