【问题标题】:Dojo dnd (drag and drop) 1.7.2 - How to maintain a separate (non-dojo-dnd) list?Dojo dnd(拖放) 1.7.2 - 如何维护一个单独的(非dojo-dnd)列表?
【发布时间】:2012-07-10 09:54:13
【问题描述】:

我正在使用 Dojo dnd 1.7.2 版,它通常运行良好。我很高兴。

我的应用维护了许多项目数组,当用户拖放项目时,我需要确保更新我的数组以反映用户看到的内容。

为了做到这一点,我想我需要在Source.onDndDrop 左右运行一些代码

如果我使用dojo.connect 在我的源上为onDndDroponDrop 设置处理程序,我的代码似乎调用得太晚了。也就是说,传递给处理程序的 source 实际上不再包含该项目。

这是一个问题,因为我想调用 source.getItem(nodes[0].id) 来获取被拖动的实际数据,以便我可以在我的数组中找到它并更新这些数组以反映用户所做的更改。

也许我做错了;还有更好的方法吗?

【问题讨论】:

    标签: dojo drag-and-drop dojo-dnd


    【解决方案1】:

    我猜有点像空白,dndSource 有几种不同的实现。但是对于在鼠标悬停/dnddrop 期间调用的事件/检查函数,有一些事情需要了解。

    一种方法是为您可能拥有的任何目标设置checkAcceptance(source, nodes)。然后保留当前拖动的节点的引用。但是会变得很棘手,因为多个容器具有动态内容。

    设置您的源,同时覆盖 checkAcceptance 并使用已知的(可能是全局的)变量来跟踪。

    var lastReference = null;
    var target = dojo.dnd.Source(node, {
        checkAcceptance(source, nodes) : function() {
            // this is called when 'nodes' are attempted dropped - on mouseover
            lastReference = source.getItem(nodes[0].id)
            // returning boolean here will either green-light or deny your drop
            // use fallback (default) behavior like so:
            return this.inhertied(arguments);
        }
    });
    

    最好的方法可能就是这样 - 您可以获得目标和源以及手头的节点,但是您需要找出哪个堆栈是在其中查找节点的正确堆栈。我相信它与事件 (onDrop) 你已经在使用:

    dojo.subscribe("/dnd/drop", function(source, nodes, copy, target) {
      // figure out your source container id and target dropzone id
      // do stuff with nodes
      var itemId = nodes[0].id
    }
    

    此处列出了通过 dojo.subscribe 和事件可用的机制/主题 http://dojotoolkit.org/reference-guide/1.7/dojo/dnd.html#manager

    【讨论】:

    • 感谢您的回复。我很感激帮助。我不知道您所说的“dndSource 有几种不同的实现”是什么意思……您能澄清一下吗?我正在使用 Source.js 中的那个。 .subscribe 技术与我在问题中描述的问题相同。如果我的订阅在内置订阅之后被调用,则该项目已从源中删除。我不希望我的程序依赖于回调的顺序。
    • 有一个特定于 dijit.Tree 的 dnd api,dojox 中有一些 .. 是 dojo/dnd/Source 吗?无论哪种方式,实现 dndSource.checkAcceptance(source, nodes) 然后 - 填写空白
    • 哦,没注意到下面的回答:p
    【解决方案2】:

    好的,我找到了一个好方法。在另一个问题的答案中发现了一个提示: https://stackoverflow.com/a/1635554/573110

    我成功的调用顺序基本上是:

    var source = new dojo.dnd.Source( element, creationParams );
    var dropHandler = function(source,nodes,copy){
      var o = source.getItem(nodes[0].id); // 0 is cool here because singular:true.
      // party on o.data ...
      this.oldDrop(source,nodes,copy);
    }
    source.oldDrop = source.onDrop;
    source.onDrop = dropHandler;
    

    这可确保在之前安装的之前调用 onDrop (dropHandler) 的新实现。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-06
      • 2013-01-12
      • 2010-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      相关资源
      最近更新 更多