简体   繁体   English

jQuery UI可拖放交互

[英]jQuery UI draggable and droppable interaction

I have a problem creating an interaction between 2 listviews. 我在2个列表视图之间创建交互时遇到问题。

I followed a solution in this thread: JQuery UI - Append Draggable to Droppable 我在此线程中遵循了一个解决方案: JQuery UI-将Draggable附加到Droppable

which is 这是

$(myDroppable).droppable({
    drop:function(event, ui) {
        ui.draggable.detach().appendTo($(this));
    }
});

However, when dropped, the li item has a weird position and I don't know what causes it. 但是,当放置li项时,它的位置很奇怪,我不知道是什么原因造成的。 JSFiddle: http://jsfiddle.net/lightbringer/W3p7d/2/ JSFiddle: http : //jsfiddle.net/lightbringer/W3p7d/2/

I created another solution myself: 我自己创建了另一个解决方案:

        $("#personlisting_assign").droppable({
        accept: "#wrapper_projectpersonlist li",
        drop: function(event, ui) {
            var el = ui.draggable[0].outerHTML;
            ui.draggable.remove();
            $("#personlist").append(el);
            $("#personlist li").removeAttr("style");
        }
    });

It works perfectly, but once an element is moved over I cannot move it back to the old list. 它可以完美工作,但是一旦将元素移到上方,我便无法将其移回旧列表。

The JSFiddle for this one is here: http://jsfiddle.net/lightbringer/W3p7d/ 这个的JSFiddle在这里: http : //jsfiddle.net/lightbringer/W3p7d/

My idea is to be freely move an item between 2 listviews. 我的想法是在2个列表视图之间自由移动项目。 And yes, I have looked at connectSortTable solution, but I want to drop an item in an area and it will be automatically add to the listview in that area. 是的,我已经看过connectSortTable解决方案,但是我想在一个区域中放置一个项目,它将自动添加到该区域中的listview中。

Could you please advise me about the two solutions above and how to fix the problems in each one. 您能为我提供上述两种解决方案以及如何解决每个问题的建议。 Thanks in advance 提前致谢

Try 尝试

    $("#personlisting_assign").droppable({
        accept: "#wrapper_projectpersonlist li",
        drop: function (event, ui) {
            ui.draggable.detach().appendTo('#personlist').removeAttr("style");
        }
    });

    $("#projectperson").droppable({
        accept: "#wrapper_personlist li",
        drop: function (event, ui) {
            ui.draggable.detach().appendTo($("#projectpersonlist")).removeAttr("style");
        }
    });

Demo: Fiddle 演示: 小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM