我使用的是Dojo dnd版本1.7.2,它通常工作得非常好。我很开心。
我的应用程序维护着许多项的数组,当用户拖放项时,我需要确保我的数组被更新以反映用户所看到的内容。
为了实现这一点,我想我需要在Source的时候运行一些代码。onDndDrop
如果我使用dojo.connect在我的源代码上为onDndDrop或onDrop设置一个处理程序,我的代码似乎调用得太晚了。也就是说,传递给处理程序的source实际上不再包含该项。
这是一个问题,因为我想调用source.getItem(nodes[0].id)来获取被拖来拖去的实际数据,这样我就可以在我的数组中找到它,并更新这些数组以反映用户所做的更改。
也许我做错了;还有更好的方法吗?
发布于 2012-07-12 05:23:56
好了,我找到了一个好方法来做这件事。在另一个问题的答案中发现了一个提示: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-11 16:57:56
我想,有几种不同的dndSource实现可以说是一片空白。但是,关于mouseover / 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
https://stackoverflow.com/questions/11421499
复制相似问题