0

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

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

为了做到这一点,我想我需要在Source.onDndDrop

如果我过去在我的 Source 上为ordojo.connect设置处理程序,我的代码似乎被调用得太晚了。也就是说,传递给处理程序的 that 实际上不再包含该项目。onDndDroponDropsource

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

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

4

2 回答 2

1

好的,我找到了一个很好的方法来做到这一点。在另一个问题的答案中发现了一个提示: 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) 的新实现在之前安装的之前被调用。

于 2012-07-11T21:23:56.010 回答
-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

于 2012-07-11T08:57:55.913 回答