我调用sortable.stop()进行ajax调用,以便在拖放操作后存储一些数据。
当ajax调用返回一个错误(应用程序逻辑错误或网络问题)时,我希望将被拖动的元素移动到它的原始/启动位置,我如何实现它?
情况应该是
sortable.stop()事件,它将触发ajax调用。stop()事件中,我们得到ajax错误步骤6-8显示为澄清连续拖动是可以完成的,必须忘记以前的错误。
发布于 2010-04-18 08:44:13
请看一看.sortable('cancel');如下所示:
var list = $('#some-list')
list.sortable(
{
// Some options.
stop: function()
{
$.post('some-url', someData, function()
{
if (somethingWentWrong)
{
list.sortable('cancel');
}
});
}
});发布于 2011-06-28 05:21:05
多亏了dafi --这对我来说很管用:
$('#some-list').sortable({
// other options here,
receive: function(event, ui) {
// ajax or function here
if(somethingWentWrong) {
$(this).sortable('cancel');
$(ui.sender).sortable('cancel');
}
}
});我不确定您是否需要$(this).sortable('cancel');,但我认为最好取消源列表和目标排序列表。这样,列表项就会立即恢复。这里还有其他可分类的选项。
发布于 2017-10-24 11:44:07
谢谢,liveat60fps,这是你只需要的两句话中的第二句。
$('#some-list').sortable({
// other options here,
receive: function(event, ui) {
// ajax or function here
if(somethingWentWrong) {
$(this).sortable('cancel');
$(ui.sender).sortable('cancel');
}
}
});这样,在一定条件下,你就可以回到原状了。
https://stackoverflow.com/questions/2661514
复制相似问题