Jquery ui 可排序放置事件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17771187/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 19:55:45  来源:igfitidea点击:

Jquery ui sortable drop event

jqueryjquery-ui-sortable

提问by user1942626

I am working with jquery ui sortable. I would like to get the sorting array to pass it to the handling file on drop event.

我正在使用可排序的 jquery ui。我想让排序数组在放置事件时将其传递给处理文件。

one funny thing i found.. http://jsfiddle.net/7Ny9h/

我发现一件有趣的事情.. http://jsfiddle.net/7Ny9h/

$(function() {
    $( "#sortable" ).sortable();
    $( "#sortable" ).disableSelection();

    $( "#sortable li" ).droppable({
        drop: function( ) {
            var order = $("#sortable").sortable("serialize", {key:'order[]'});
            $( "p" ).html( order );
        }
    });
});

Seeing the sample, if I move BOX No.2, the BOX 2 is left out of the array.

查看示例,如果我移动 BOX No.2,则 BOX 2 会被排除在阵列之外。

Perhaps I need a kind of "dropend" event because it seems that jquery ui drop event doesn't count the dragged and dropped one.

也许我需要一种“dropend”事件,因为 jquery ui drop 事件似乎不计算拖放事件。

回答by Ari

You can also use updateto detect it.

您也可以使用update它来检测它。

$( "#sortable" ).sortable({
    update: function( ) {
        // do stuff
    }
});

回答by user1942626

I could solve the problem with jQuery UI Sortable stopevent.

我可以用 jQuery UI Sortablestop事件解决这个问题。

$(function() {
    $( "#sortable" ).sortable();
    $( "#sortable" ).disableSelection();

    $( "#sortable" ).sortable({
        stop: function( ) {
            var order = $("#sortable").sortable("serialize", {key:'order[]'});
            $( "p" ).html( order );
        }
    });
});