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

问题描述 投票:5回答:4

我正在尝试使用Jquery&Php进行类别更改。我没问题。我的问题是,当调用update事件时,它返回2个结果。拖动父项的1个结果,Dropped Parent的一个结果。我想只打电话给父母的身份。这是我的脚本:

$("#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();

你能帮帮我们吗?

jquery draggable jquery-ui-sortable
4个回答
7
投票

例如,使用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
投票

你应该尝试使用sortable不同的活动

  • 开始
  • 分类
  • 更改
  • beforeStop
  • 更新
  • 接收
  • 去掉
  • 过度
  • 启用
  • 关闭

我很确定其中一个会是你的答案。

资料来源:http://jqueryui.com/demos/sortable/#event-change


0
投票

这样做:

  update: function(event, ui) {
            if(ui.sender) {
             // Your actual code
            }
        },
© www.soinside.com 2019 - 2024. All rights reserved.