Jquery可排序更新事件只能调用一次吗?

5
我正在尝试使用Jquery和Php进行分类更改。我没有问题。我的问题是,当调用更新事件时,它返回2个结果。一个是拖动的父级别,另一个是放置的父级别。我只想调用放置的父级别的ID。这是我的脚本:
$("#gallery ul").sortable({
    connectWith: '.dropBox',
    opacity: 0.35,
    scroll: true, 
    scrollSensitivity: 100,
    //handle: '.move',
    helper: 'clone',
    containment:'#gallery',
    accept:'#gallery > .photo',
    revert: true,
    update: function(event, ui){
        params = 'c=' + $(this).attr('id') + '&id=' + ui.item.attr('id');

        $.ajax({
            type: 'POST',
            url: 'processData.php',
            data: params,
            error:function(){
                alert("Error!");
            },
            success:function(data){
                $("#serverResponse").html(data);
            }
        });
    }
}).disableSelection();

你们能帮帮我吗?
4个回答

9

例如,使用updatestopreceive事件。

$(function() {
    position_updated = false; //flag bit

    $(".sortable").sortable({
        connectWith: ".sortable",

        update: function(event, ui) {
            position_updated = !ui.sender; //if no sender, set sortWithin flag to true
        },

        stop: function(event, ui) {
            if (position_updated) {

                //code

                position_updated = false;
            }
        },

        receive: function(event, ui) {
            // code
        }

    }).disableSelection();
});

3
ui.sender 只存在于第二个回调函数中。
$(".sortable").sortable({
    connectWith: ".sortable",
    update: function (evt, ui) {
        // just ignore the second callback
        if(ui.sender == null){
            // call ajax here
        }
    },
    receive: function (evt, ui) {
        // called after the first 'update'
        // and before the second 'update'
        // ui.sender is always exists here
    }
}).disableSelection();

1

只需这样做:

  update: function(event, ui) {
            if(ui.sender) {
             // Your actual code
            }
        },

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接