JQuery UI Sortable 接收前禁用更新功能
我正在使用 jquery ui 处理一个列表,您可以在其中排序,然后也在另一个列表之间排序。我正在使用更新进行内部排序,效果很好。当我在两者之间排序时,我只想调用接收函数而不是更新。目前,更新被调用,然后接收被调用。在列表之间排序时有什么方法可以跳过更新调用吗?
<script>
$ = jQuery
$(function() {
$( "#sortable1).sortable({
connectWith: ".connectedSortable",
placeholder: "ui-state-highlight",
update: function(event, ui) {processSortWithin(ui.item.attr("id"), ui.item.index()); },
receive: function(event, ui){
processSortBetween(ui.item.attr("id"), ui.item.index(),ui.sender.attr("id"));
}
}).disableSelection();
});
</script>
I'm using jquery ui to process a list that you can sort within and then also sort between another list. I'm using the update for the sorting within and that works fine. When I sort between I just want to call the receive function and not the update. Currently, update gets called and then receive gets called. Is there any way to skip the update call when sorting between lists?
<script>
$ = jQuery
$(function() {
$( "#sortable1).sortable({
connectWith: ".connectedSortable",
placeholder: "ui-state-highlight",
update: function(event, ui) {processSortWithin(ui.item.attr("id"), ui.item.index()); },
receive: function(event, ui){
processSortBetween(ui.item.attr("id"), ui.item.index(),ui.sender.attr("id"));
}
}).disableSelection();
});
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
答案来自: http://forum.jquery.com/topic/sortables-更新回调和连接
Answer from: http://forum.jquery.com/topic/sortables-update-callback-and-connectwith
我今天遇到了类似的问题,我找到的唯一解决方案是引入一个标志变量,该变量在 update 事件期间设置,并在 stop 事件期间检查。
在您的示例中,您使用 receive 事件,该事件将在从其他列表接收新元素的列表上触发,因此应将其设置在
$(".connectedSortable").sortable( )
选项。以下是我区分是否排序(在一个列表内,在 stop 中处理)或移动(在两个列表之间,在 receive 中处理)的方法:
工作示例:http://jsfiddle.net/myLff/2/
I had a similar problem today, and the only solution I found was to introduce a flag variable that is set during update event, and checked during stop event.
In your example, you use receive event which will be fired on the list that receives new element from some other list, so it should be set inside
$(".connectedSortable").sortable()
options.Here is my way to distinguish whether to sort (within one list, processed in stop) or to move (between two lists, processed in receive):
Working example: http://jsfiddle.net/myLff/2/
试试这个:
Try this: