【问题标题】:Copy Item from One static list to another and revert as well将项目从一个静态列表复制到另一个静态列表并还原
【发布时间】:2015-11-30 16:40:21
【问题描述】:

我有两个列表。 ListOneListTwoListTwo 中有 1-5 个项目,想要将所需项目拖动到 ListOne,最初将为空白,该项目将添加到 ListOne,但不会从 ListTwo 中删除该项目。我已经完成到这里了。

问题:当我想将项目从ListOne 拖到ListTwo 时,应该从ListOne 中删除此项目,但不应将其添加到ListTwo。这没有发生。

简单来说,我希望 ListTwo 是静态的。

这是我的小提琴链接。http://jsfiddle.net/hQnWG/1596/

【问题讨论】:

    标签: jquery jquery-ui jquery-mobile jquery-ui-draggable jquery-ui-sortable


    【解决方案1】:

    这里有一个解决方案。我将 sortable1 连接到 sortable2 并在 sortable2 上使用了一个接收处理程序,以便在它被移动时移除它。

    $(function() {
        $("#sortable2").sortable({
            connectWith: "#sortable1",
    
            helper: function (e, li) {
                this.copyHelper = li.clone().insertAfter(li);
    
                $(this).data('copied', false);
    
                return li.clone();
            },
            stop: function () {
    
                var copied = $(this).data('copied');
    
                if (!copied) {
                    this.copyHelper.remove();
                }
    
                this.copyHelper = null;
            },
    
            receive: function(e, ui){
                $(ui.item[0]).remove();
            }
        });
    
        $("#sortable1").sortable({
            connectWith: "#sortable2",
            receive: function (e, ui) {
                ui.sender.data('copied', true);
            }
        });
    
        $("#sortable1").on("click", "li", function () {
    
    
        });   
    });
    

    http://jsfiddle.net/jufcd4y8/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-12
      • 1970-01-01
      相关资源
      最近更新 更多