jQuery UI Sortable:在拖动时列表更改时维护sortable-helper [英] jQuery UI Sortable: maintain sortable-helper as list changes when dragging

查看:241
本文介绍了jQuery UI Sortable:在拖动时列表更改时维护sortable-helper的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个元素列表,并且可以使用jQuery UI Sortable拖动列表并对其进行排序.现在,棘手的部分是该列表在不断变化.有推送请求,并且此列表随着您的拖动而增长.除了用户拖动并添加新列表项时,所有工作正常,但无法在此实时列表中对sortable-helper(正在拖动的列表项)进行排序.我最终遇到错误:无法调用null的方法'insertBefore'".我曾尝试调用$(#sortable").sortable("refresh"),但这在您使用列表时似乎对列表没有影响.

I have a list of elements and using jQuery UI Sortable I'm able to drag and sort the list. Now the tricky part is that this list is constantly changing. There are push requests and this list grows as you are dragging. I have everything working except when a user is dragging and new list items are added, the sortable-helper (the list item being dragged) is unable to be sorted in this realtime list. I end up with the error: "Cannot call method 'insertBefore' of null". I have tried calling $("#sortable").sortable("refresh") but that seems to have no impact on the list as you are using it.

<ul id="sortable">
    <li>one</li>
    <li>two</li>
    <li>three</li>
</ul>

是否有一种方法可以维护在此实时列表更新时用户拖动的sorting-helper?

Is there a way to maintain the sortable-helper that the user is dragging as this realtime list is updating?

谢谢!

推荐答案

开始拖动项目时,需要锁定列表.这可以通过简单地使用变量:var list_locked = 1;来实现,该变量在将更多列表项添加到列表之前进行检查.将项目动态添加到列表的机制将需要等待list_locked = 0,然后安全地添加更多项目.传入项可以存储在数组中.当用户开始拖动并开始对列表进行排序时,jQuery UI会发出一些事件.使用这些事件可以知道何时锁定列表.

When you begin dragging an item, you will need to lock the list. This can be accomplished by simply using a variable ie: var list_locked = 1; that is checked before more list items are added to the list. The mechanism that dynamically adds items to the list will need wait for list_locked = 0 before safely adding more items. The incoming items could be stored in an array. There are events that are issued by jQuery UI when the user begins dragging and when the user begins sorting a list. Use these events to know when to lock the list.

这篇关于jQuery UI Sortable:在拖动时列表更改时维护sortable-helper的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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