jQuery Sortable-事件被调用太多次 [英] jQuery Sortable - events being called too many times

查看:193
本文介绍了jQuery Sortable-事件被调用太多次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类别为x的列表,其中有许多类别为y的列表.

I have a list with class x and in that list is a number of lists with class y.

可以将项目从任何子列表拖动到任何其他子列表

It is possible to drag an item from any of the sublists to any of the other sublists

还可以安排子列表本身的顺序.

It is also possible to arrange the order of the sublists themselves.

我正在努力应对可排序事件引发的事件

I'm struggling with the events which are fired through the sortable

接收-仅在将某物从其他地方带入列表时触发(因此不利于安排子列表中的项目或安排子列表本身)

Receive - only triggers when something is brought into a list from elsewhere (so no good for arranging items in sublists or for arranging the sublists themselves)

更新-当我将项目从子列表A拖到子列表B时,似乎触发了多次(我假设子列表A正在更新,子列表B正在更新).

Update - seems to trigger multiple times when I drag an item from sublist A to sublist B (I assume as sublist A is being updated and sublist B is being updated).

我的JS中有一个函数,可将列表和子列表中的当前布局同步到数据库,并且不想一次执行多次.

I have a function in my JS which syncronises the current layout in the lists and sublists to the database and don't want to do this more than once at a time.

这些事件的组合似乎都没有给我想要的行为.这是正确的路线吗?还是可以通过某种方式对每五秒钟运行一次的Sync方法进行计划调用,以保存更改并忽略实际事件本身?

No combination of these events seems to give me the desired behaviour at all. Is this the right route to take? Or is there someway I can do a scheduled call to the Sync method which runs every 5 seconds or so to save changes and ignore the actual events themselves?

推荐答案

您应该使用stop事件更新有序列表.

You should use the stop event for updating the ordered list.

例如:

        $("#List .Items").sortable({
            stop: function(e, ui) { 
                // update items
            }
        });

这篇关于jQuery Sortable-事件被调用太多次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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