EasyUI Forum
May 08, 2024, 12:26:58 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Copy node between trees  (Read 7977 times)
maxam
Newbie
*
Posts: 3


View Profile
« 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?
Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #1 on: December 19, 2014, 03:38:01 AM »

You may need to show some code snippets to demonstrate your issue.
Logged
maxam
Newbie
*
Posts: 3


View Profile
« Reply #2 on: December 21, 2014, 02:43:00 AM »

Providing minimal working example

Code:
<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]
Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #3 on: December 21, 2014, 07:37:54 AM »

Please try to create a deep copy of the source node before appending it.
Code:
<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>
Logged
maxam
Newbie
*
Posts: 3


View Profile
« Reply #4 on: December 22, 2014, 09:52:43 AM »

@jarry

Thanks very much. That solved the issue.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!