jQuery UI Sortable:如果更新回调进行的AJAX调用失败,是否还原更改? [英] jQuery UI Sortable: Revert changes if update callback makes an AJAX call that fails?

查看:62
本文介绍了jQuery UI Sortable:如果更新回调进行的AJAX调用失败,是否还原更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用可排序的小部件对项目列表进行重新排序.将项目拖动到新位置后,我启动了AJAX表单发布到服务器以保存新订单.如果我从服务器收到错误消息,该如何撤消排序(例如,将拖动项返回到列表中的原始位置)?

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 I undo the sort (e.g. return the drag item to its original position in the list) if I receive an error message from the server?

基本上,如果服务器确认更改已保存,我只希望重新排序粘".

Basically, I only want the re-order to "stick" if the server confirms that the changes were saved.

推荐答案

我很确定sortable没有任何undo-last-drop功能-但这是个好主意!

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

我认为最好的办法是编写某种存储顺序的start,然后在失败时调用还原函数. IE.像这样的东西:

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.

这篇关于jQuery UI Sortable:如果更新回调进行的AJAX调用失败,是否还原更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆