Title: Copy node between trees
Post by: maxam on December 19, 2014, 02:27:09 AM
I try to copy, a node between two trees by means of dnd. The target tree has a onBeforeDrop method declared, which appends a new node with data copied from the source and returns false. However when i try to repeat the copy procedure on the node used previously copied node I got error: _db is null source is null
I assume that it is because 'return false' only affects the target tree, not source tree. Any ideas how to over come this?
Title: Re: Copy node between trees
Post by: jarry on December 19, 2014, 03:38:01 AM
You may need to show some code snippets to demonstrate your issue.
Title: Re: Copy node between trees
Post by: maxam on December 21, 2014, 02:43:00 AM
Providing minimal working example
<ul id="groupstree" class="easyui-tree tree" data-options="animate:true,dnd:true, onBeforeDrop: function(target,source,point){
if( source.attributes.source == 'person_tree' ){
toAppend = source; toAppend.attributes.source = 'big_tree';
$(this).tree('append', { parent: target, data: toAppend, });
return false; } }, onAfterEdit: function(e, node) { editName(e); }, data:[ {'id':37,'text':'Group','attributes':{'node_type':'group','source':'big_tree'},'children':[{'id':-1,'text':'People','attributes':{'node_type':'people','source':'big_tree'},'state':'closed','children':[{'id':155,'text':'foo bar (foobar)','attributes':{'node_type':'person','source':'big_tree'}},{'id':157,'text':'test test (test)','attributes':{'node_type':'person','source':'big_tree'}},{'id':5,'text':'foo1 bar1','attributes':{'node_type':'person','source':'big_tree'}},]}]}, ] "></ul> <div class="collections"> <ul id="peopletree" class="easyui-tree tree" data-options="animate:true,dnd:true, onDragEnter: function(target,source){ if(source.attributes.source != null ) return false; }, data:[ {'id':187,'text':'malenki asd (malenki)','attributes':{'node_type':'person','edited':false,'source':'person_tree'},'checked':'true'},{'id':160,'text':'asdfsadf asfasdfsa (sdfasdf)','attributes':{'node_type':'person','edited':false,'source':'person_tree'},'checked':'true'}, ] "></ul> [code] [/code]
Title: Re: Copy node between trees
Post by: jarry on December 21, 2014, 07:37:54 AM
Please try to create a deep copy of the source node before appending it. <ul id="groupstree" class="easyui-tree tree" data-options=" animate:true,dnd:true, onBeforeDrop: function(target,source,point){ if( source.attributes.source == 'person_tree' ){ toAppend = $.extend(true,{},source); toAppend.attributes.source = 'big_tree'; $(this).tree('append', { parent: target, data: toAppend, }); return false; } }, </ul>
Title: Re: Copy node between trees
Post by: maxam on December 22, 2014, 09:52:43 AM
@jarry
Thanks very much. That solved the issue.
|