拖动 Draggable 时添加 Droppable

发布于 2024-10-12 08:38:39 字数 427 浏览 8 评论 0原文

期望的行为:

用户将一个项目拖到树上。将鼠标悬停在关闭的节点上时,该节点会展开以显示子节点。此时,用户可以继续拖动到子节点并将其放在其中的任何一个上。

这工作得很好。我使用 droppables 的“over”选项来展开节点并使子节点可放置。

但我需要添加更多功能。首先,我添加了一个可拖动的助手。仍然工作正常。然后我将可拖动对象和可放置对象放入两个不同的容器(div)中。此时,助手就不会被拖出容器了。解决方案是在可拖动对象上设置“appendTo: 'body'”。一切都很好……好吧,不完全是。

现在,在当前拖动操作期间,子节点不可被放置。用户必须释放当前的拖动并重新拖动到所需的子节点。如果我删除appendTo选项,问题就会消失,但助手不会在视觉上移动到可放置容器中。

有什么方法可以“唤醒”这些新的可放置物品,使它们立即可放置吗?

The desired behavior:

The user drags an item onto a tree. Upon hovering over a closed node, the node expands revealing the children. At this point the user can continue dragging to the child nodes and drop on any of them.

This was working fine. I use the "over" option of the droppables to expand the node and make the children droppable.

But I needed to add some more features. First I added a helper for draggables. Still working fine. Then I put the draggables and droppables into two different containers (divs). At this point, the helper would not drag out of the container. The solution was to set "appendTo: 'body'" on the draggables. All good...well, not quite.

Now the child nodes are not droppable during the current drag operation. The user must release the current drag and redrag into the desired child node. If I remove the appendTo option, the problem goes away, but then the helper does not visually move into the droppable container.

Is there some way that I can "wake up" these new droppables to make them immediately droppable?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧情勿念 2024-10-19 08:38:39

这就是我解决几乎相同问题的方法。就我而言,当我在拖动可拖动对象期间打开节点时,子项目将通过 ajax 加载,然后将它们初始化为可放置对象。然后我必须这样做:

ui.draggable.draggable('option', 'refreshPositions', true);
var tempFunc = function() {
    if (ui.draggable) {
        ui.draggable.off('drag', tempFunc);
        setTimeout(function() {
            ui.draggable.draggable('option', 'refreshPositions', false);
        }, 100);
    }
};
ui.draggable.on('drag', tempFunc);

这使得可拖动的 refreshPositions 选项设置为 true 足够长的时间,以便新的可放置项加入当前的拖动。您还可以在整个拖动过程中将 refreshPositions 选项设置为 true,但它会带来我不希望的性能损失。

我没有找到用另一种方式做到这一点的方法。如果有一个方法可以在拖动期间调用以刷新位置,那就最好了,但没有。

This is how I got almost same problem solved. In my case when I toggle the node open during dragging a draggable, child items are loaded via ajax and then they are initialized as droppables. Then I have to do this:

ui.draggable.draggable('option', 'refreshPositions', true);
var tempFunc = function() {
    if (ui.draggable) {
        ui.draggable.off('drag', tempFunc);
        setTimeout(function() {
            ui.draggable.draggable('option', 'refreshPositions', false);
        }, 100);
    }
};
ui.draggable.on('drag', tempFunc);

This makes the draggable have refreshPositions option as true long enough for the new droppables to join the current drag. You can also have the refreshPositions option be true during the whole drag, but it gives a performance penalty which I don't want.

I didn't find a way to do it in another way. It would be best if there was a method you could call during the drag just for refreshing the positions, but there isn't.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文