jQuery Sortable-替换项目而不是交换项目 [英] Jquery Sortable - Replacing Items rather than swapping items

查看:240
本文介绍了jQuery Sortable-替换项目而不是交换项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何可配置的选项来实现功能,例如替换列表项而不是在JQuery Sortable UI中交换项目.当前功能类似于Item1与Item2交换,反之亦然.我需要类似的功能,如果将item2拖放到Item1上,则item2应该替换Item1,而Item2的位置将为空.有什么帮助吗?谢谢.

Is there any configurable option to achieve the feature like replacing the list items rather than swapping items in JQuery Sortable UI. Current feature is like Item1 Swaps with Item2 and vice versa. I need a feature like, If item2 is dragged and dropped on Item1, item2 should replace Item1 and Item2 position will be empty. Any help? thanks.

推荐答案

您可以使用以下代码进行操作:

You can do it with the following code:

$('#container').sortable({
  connectWith: '#container',
  items: '.children', //#container > .children
  cursor: 'move',
  receive: function(event, ui) {
    var item = $(ui.item);
    var sender = $(ui.sender);
    sender.append(item.siblings('.children'));
  }
});

这篇关于jQuery Sortable-替换项目而不是交换项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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