Jquery-UI可排序:如何判断在停止回调中是否取消了排序?

时间:2022-09-10 14:08:43

I set up a sortable with stop callback and binded esc to cancel current sorting. In stop callback, how can I tell if current sorting was canceled or completed?

我设置了一个带有停止回调和绑定esc的可排序,以取消当前的排序。在停止回调中,如何判断当前排序是否已取消或完成?

Here is my current snippet:

这是我目前的片段:

this.$("tbody").sortable({
    start: function() {
        shortcut.add("esc", function() {
            that.$("tbody").sortable("cancel");
        });
    },
    handle: ".sortable-handle",
    stop: function(e, ui) {
        shortcut.remove("esc");
        // how to check if cancel was called during sorting?
        if (!e.canceled) {
            // save new state 
        }
    }
});

1 个解决方案

#1


Inside the stop function try this.

在停止功能内试试这个。

stop: function(e, ui) {
    if(ui.item.sortable._isCanceled) {
        console.log('Sort action was canceled');
    } else {
        console.log('Sort action was not canceled');
    }
}

#1


Inside the stop function try this.

在停止功能内试试这个。

stop: function(e, ui) {
    if(ui.item.sortable._isCanceled) {
        console.log('Sort action was canceled');
    } else {
        console.log('Sort action was not canceled');
    }
}