1

リストを並べ替えると、アイテムをドロップするとすぐに、バックエンド コードに位置が送信され、バックエンドでリストが並べ替えられます。ただし、非常に高速に並べ替えると、しばらくするとフロントエンドとバックエンドのリストが同期しなくなる場合がありました。そのため、競合状態を避けるために、ドロップした直後にドラッグを無効にしたいと考えています。

function reorder(panelId, type){
    $(escapeClientId(panelId)).sortable({
        start: function(event, ui){
            ui.item.startPos = ui.item.index();
        },
        stop: function(event, ui){
            //submit my start and end position to the server
            //change the cursor to wait
            $('body').css('cursor', 'wait');
            window.setTimeout(wait,600);                                    
        }
    });
    $(escapeClientId(panelId)).disableSelection();
}
function wait(){
    $('body').css('cursor', 'default');
}

ご覧のとおり、カーソルを 600 ミリ秒のカーソルに変更しますがwait、カーソルが待機モードの場合でも、ユーザーはドラッグして並べ替えることができます。ドロップ直後の一瞬だけドラッグを完​​全に無効にする方法はありますか?

4

1 に答える 1

2

disableメソッドとenableメソッドの使用を試すことができます。

function reorder(panelId, type) {
    $(escapeClientId(panelId)).sortable({
        start: function (event, ui) {
            ui.item.startPos = ui.item.index();
        },
        stop: function (event, ui) {
            var panel = $(this), 
                body = $('body');

            panel.sortable("disable"); // Disable before submitting.
            body.css('cursor', 'wait');

            //submit my start and end position to the server
            //change the cursor to wait

            setTimeout(function () {
                body.css('cursor', 'default');
                panel.sortable("enable");
            }, 500); // Enable after 500 ms.
        }
    });
    $(escapeClientId(panelId)).disableSelection();
}
于 2012-11-30T23:11:44.103 に答える