jQuery UI Sortable - 更新事件,从连接列表中调用两次排序项

时间:2018-04-09 13:14:06

标签: angularjs jquery-ui jquery-ui-sortable

我有多个UI可排序列表。我遇到的问题是,当我将列表A中的项目排序到列表B时,更新函数会被触发两次。我认为这是因为它正在更新位置并更新列表。

无论如何,要处理来自connectedList的可排序项目,我正在使用receive函数。我处理列表中新项目的所有逻辑都放在那里。

我想使用update函数来处理同一列表中的排序。

$scope.sortableEpics = {
        connectWith : '.sortableEpics',
        items : '.expanded-epic',
//      tolerance : 'pointer',
        helper : 'clone',
        axis: 'y',
        delay: 200,
        start : function(e, ui){
            previousGoal = $(e.target).attr("data-goal-id"); // On sortStart, set previousGoal to compare on sortUpdate if sortable item has moved lists
            $scope.draggingEpic = true; // If draggingEpic is true, stacked epics become 'droppable/draggable'
            $scope.$apply();
        },
        stop : function(e, ui){
            $scope.draggingEpic = false; // If draggingEpic is false, prevent dragging of stacked epics
            $scope.$apply();
        },
        update : function(e, ui){
            currentGoal = $(e.target).attr("data-goal-id");
            if(ui.sender) return; 
            if(currentGoal !== previousGoal) return; // Only execute following code if sortable is dropped within the same list

            /* Logic for a new position in the list goes here */
        },
        receive : function(e,ui){
            /* Logic for receiving a new item to the list goes here */
        }
    };

这里的问题是第一次调用更新函数时没有附加新的goal_id,所以currentGoal === previousGoal总是在第一次调用中。

在第二次调用中,它已更新,并且从函数返回的比较有效。

我想要的是第一次阻止更新函数的调用,我已经尝试检查事件和ui对象,但是在同一列表中拖放它们时看起来相同。

如何在第一次调用更新函数时检测到可排序项目已移动列表并阻止进一步执行该函数?

0 个答案:

没有答案