JQuery UI可排序在接收之前禁用更新功能

c12*_*c12 8 jquery jquery-ui jquery-ui-sortable

我正在使用jquery ui来处理您可以在其中排序的列表,然后在另一个列表之间进行排序.我正在使用更新进行排序,并且工作正常.当我在中间排序时,我只想调用接收函数而不是更新.目前,更新被调用,然后接收被调用.在列表之间进行排序时,有没有办法跳过更新调用?

<script>
            $ = jQuery
            $(function() {
                $( "#sortable1).sortable({
                    connectWith: ".connectedSortable",
                    placeholder: "ui-state-highlight",
                    update: function(event, ui) {processSortWithin(ui.item.attr("id"), ui.item.index()); },
                    receive: function(event, ui){ 
                        processSortBetween(ui.item.attr("id"), ui.item.index(),ui.sender.attr("id"));
                    }
                }).disableSelection();
            });

        </script>
Run Code Online (Sandbox Code Playgroud)

Ste*_*fan 13

答案来自:http://forum.jquery.com/topic/sortables-update-callback-and-connectwith

update: function(e,ui) {
    if (this === ui.item.parent()[0]) {
        //your code here
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 这将区分列表中的排序和从列表中删除元素,但不区分列表中的排序和从另一个列表接收项目.要做到这一点,你需要结合这个答案和@MarkN的答案,`if(!ui.sender && this === ui.item.parent()[0]){/*在列表中排序......*/} ` (2认同)