I am working on code like the following.
01: var c1 = new dojo.dnd.Source('container1', {copyOnly:true}); // container1 is a div
02: var c2 = new dojo.dnd.Source('container2'); // container2 is a div
03: var list = [];
04: for (var i = 0; i < 3; i++) { list.push( dojo.create('div') ); }
05: c1.insertNodes(false, list);
06:
07: function checkDndCopy(nodes, target){
08: dojo.forEach(nodes, function(node){ alert(node.id); } );
09: }
10: dojo.subscribe("/dnd/drop", function(){
11: var mgr = dojo.dnd.manager();
12: checkDndCopy(mgr.nodes, mgr.target);
13: });
The nodes inserted to the c1 at line 05 have id of "dojoUnique1, donoUnique2, dojoUnique3". On a event of drag and drop a node from c1 to c2, a onDndDrop event is fired and the subscribe method defined in line10-13 is invoked.
I expected that newly copied node appears in the nodes (for example) at line 08. But this is not true. When dojoUnique1 is target of drag and drop, nodes at line 08 contains only dojoUnique1.
I want to modify some attributes of newly copied nodes on the event of onDndDrop. Please let me know how such a thing is realized.
I'm not sure, if it is the only (and best) way, but you may write your own node creator to override dropped node and avatar creation. Example below extends your code and makes dropped nodes red:
You can find more information about writing own creators here and in google
Based on the way of using custom creator, I found following.
Function createCopyItem() is out of scope. It is necessary to copy
item
and modify the new object becauseitem
cannot be placed both under its original parentNode and undernode
created in myCreator().First, as a rule of thumb try to avoid using DnD topics especially for local things — they are cumbersome to use because by the time your function is called parameters can be modified or even destroyed by other processors (as you already discovered). Use local events and/or override methods. If you want to do something to newly inserted nodes just override
onDrop
(oronDropExternal
, oronDropInternal
, if you want to handle only specific drops).Another useful hint: newly inserted nodes are selected.
Let's code it up:
If you allow to rearrange lists and want to do the modifications only for external drops (e.g., from c1 to c2), you should override
onDropExternal
. The code will be the same.Because this example doesn't rely on original items, you can do it with topics but you may need some extra code if you want to do it conditionally (e.g., for c2, but not c1). If you don't care about any other things, it is actually pretty easy too: