jQuery UI Sortable: Revert changes if update callback makes an AJAX call that fails?

后端 未结 3 952
情书的邮戳
情书的邮戳 2021-02-04 00:58

I am using the sortable widget to re-order a list of items. After an item is dragged to a new location, I kick off an AJAX form post to the server to save the new order. How can

3条回答
  •  礼貌的吻别
    2021-02-04 01:39

    I'm pretty sure that sortable doesn't have any undo-last-drop function -- but it's a great idea!

    In the mean time, though, I think your best bet is to write some sort of start that stores the ordering, and then on failure call a revert function. I.e. something like this:

    $("list-container").sortable({
      start: function () { 
               /* stash current order of sorted elements in an array */
             },
      update: function () {
              /* ajax call; on failure, re-order based on the stashed order */
             }
    });
    

    Would love to know if others have a better answer, though.

提交回复
热议问题