|  | @@ -122,12 +122,12 @@ var idTree = {
 | 
	
		
			
				|  |  |              },
 | 
	
		
			
				|  |  |              addUpdateDataForParent: function (datas, nodes, pid) {
 | 
	
		
			
				|  |  |                  nodes.forEach(function (node) {
 | 
	
		
			
				|  |  | -                    datas.push({type: 'update', data: node.tree.getDataTemplate(node.getID(), pid, node.getNextSiblingID())});
 | 
	
		
			
				|  |  | +                    datas.push({ type: 'update', data: node.tree.getDataTemplate(node.getID(), pid, node.getNextSiblingID()) });
 | 
	
		
			
				|  |  |                  });
 | 
	
		
			
				|  |  |              },
 | 
	
		
			
				|  |  |              addUpdateDataForNextSibling: function (datas, node, nid) {
 | 
	
		
			
				|  |  |                  if (node) {
 | 
	
		
			
				|  |  | -                    datas.push({type: 'update', data: node.tree.getDataTemplate(node.getID(), node.getParentID(), nid)});
 | 
	
		
			
				|  |  | +                    datas.push({ type: 'update', data: node.tree.getDataTemplate(node.getID(), node.getParentID(), nid) });
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          };
 | 
	
	
		
			
				|  | @@ -222,14 +222,14 @@ var idTree = {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          // 获取节点所有后代节点
 | 
	
		
			
				|  |  | -        Node.prototype.getPosterity = function() {
 | 
	
		
			
				|  |  | +        Node.prototype.getPosterity = function () {
 | 
	
		
			
				|  |  |              let posterity = [];
 | 
	
		
			
				|  |  |              getNodes(this.children);
 | 
	
		
			
				|  |  |              return posterity;
 | 
	
		
			
				|  |  |              function getNodes(nodes) {
 | 
	
		
			
				|  |  |                  for (let node of nodes) {
 | 
	
		
			
				|  |  |                      posterity.push(node);
 | 
	
		
			
				|  |  | -                    if (node.children.length > 0){
 | 
	
		
			
				|  |  | +                    if (node.children.length > 0) {
 | 
	
		
			
				|  |  |                          getNodes(node.children);
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  |                  }
 | 
	
	
		
			
				|  | @@ -237,12 +237,12 @@ var idTree = {
 | 
	
		
			
				|  |  |          };
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          // 担心链有问题,preSibling不靠谱的话,按照显示顺序算preSibling
 | 
	
		
			
				|  |  | -        Node.prototype.prevNode = function() {
 | 
	
		
			
				|  |  | +        Node.prototype.prevNode = function () {
 | 
	
		
			
				|  |  |              const parent = this.parent || this.tree.roots;
 | 
	
		
			
				|  |  |              if (!parent) {
 | 
	
		
			
				|  |  |                  return null;
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            const children = parent === this.tree.roots ? this.tree.roots :  parent.children;
 | 
	
		
			
				|  |  | +            const children = parent === this.tree.roots ? this.tree.roots : parent.children;
 | 
	
		
			
				|  |  |              const index = children.indexOf(this);
 | 
	
		
			
				|  |  |              return children[index - 1] || null;
 | 
	
		
			
				|  |  |          }
 | 
	
	
		
			
				|  | @@ -297,12 +297,12 @@ var idTree = {
 | 
	
		
			
				|  |  |                      tools.addUpdateDataForNextSibling(data, this.preSibling, this.tree.setting.rootId);
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |                  tools.addUpdateDataForNextSibling(data, this.parent, this.getID());
 | 
	
		
			
				|  |  | -                data.push({type: 'update', data: this.tree.getDataTemplate(this.getID(), this.parent.getParentID(), this.parent.getNextSiblingID())});
 | 
	
		
			
				|  |  | +                data.push({ type: 'update', data: this.tree.getDataTemplate(this.getID(), this.parent.getParentID(), this.parent.getNextSiblingID()) });
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              return data;
 | 
	
		
			
				|  |  |          };
 | 
	
		
			
				|  |  |          Node.prototype.upLevel = function () {
 | 
	
		
			
				|  |  | -            var result = {success: false, updateDatas: []};
 | 
	
		
			
				|  |  | +            var result = { success: false, updateDatas: [] };
 | 
	
		
			
				|  |  |              var iIndex = this.parent.children.indexOf(this), orgParent = this.parent, newNextSibling = this.parent.nextSibling;
 | 
	
		
			
				|  |  |              if (this.canUpLevel) {
 | 
	
		
			
				|  |  |                  // NextSiblings become child
 | 
	
	
		
			
				|  | @@ -329,7 +329,7 @@ var idTree = {
 | 
	
		
			
				|  |  |                      tools.addUpdateDataForNextSibling(data, this.preSibling.lastChild(), this.getID());
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |                  tools.addUpdateDataForNextSibling(data, this.preSibling, this.getNextSiblingID());
 | 
	
		
			
				|  |  | -                data.push({type: 'update', data: this.tree.getDataTemplate(this.getID(), this.preSibling.getID(), this.tree.setting.rootId)});
 | 
	
		
			
				|  |  | +                data.push({ type: 'update', data: this.tree.getDataTemplate(this.getID(), this.preSibling.getID(), this.tree.setting.rootId) });
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              return data;
 | 
	
		
			
				|  |  |          };
 | 
	
	
		
			
				|  | @@ -533,7 +533,7 @@ var idTree = {
 | 
	
		
			
				|  |  |          Tree.prototype.insert = function (parentID, nextSiblingID) {
 | 
	
		
			
				|  |  |              var newID = this.newNodeID(), node = null, data = {};
 | 
	
		
			
				|  |  |              var parent = parentID == -1 ? null : this.nodes[this.prefix + parentID];
 | 
	
		
			
				|  |  | -            var nextSibling = nextSiblingID == -1 ? null: this.nodes[this.prefix + nextSiblingID];
 | 
	
		
			
				|  |  | +            var nextSibling = nextSiblingID == -1 ? null : this.nodes[this.prefix + nextSiblingID];
 | 
	
		
			
				|  |  |              if (newID !== -1) {
 | 
	
		
			
				|  |  |                  data = {};
 | 
	
		
			
				|  |  |                  data[this.setting.id] = newID;
 | 
	
	
		
			
				|  | @@ -551,24 +551,24 @@ var idTree = {
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              return node;
 | 
	
		
			
				|  |  |          };
 | 
	
		
			
				|  |  | -        Tree.prototype.m_insert = function (datas,parentID, nextSiblingID) {
 | 
	
		
			
				|  |  | -           // var newID = this.newNodeID(), node = null, data = {};
 | 
	
		
			
				|  |  | +        Tree.prototype.m_insert = function (datas, parentID, nextSiblingID) {
 | 
	
		
			
				|  |  | +            // var newID = this.newNodeID(), node = null, data = {};
 | 
	
		
			
				|  |  |              var parent = parentID == -1 ? null : this.nodes[this.prefix + parentID];
 | 
	
		
			
				|  |  | -            var nextSibling = nextSiblingID == -1 ? null: this.nodes[this.prefix + nextSiblingID];
 | 
	
		
			
				|  |  | -            let preInsertNode = null,nodes = [];
 | 
	
		
			
				|  |  | -            for(let d of datas){
 | 
	
		
			
				|  |  | -                let node = new Node(this,d.data);
 | 
	
		
			
				|  |  | -                if(preInsertNode == null){
 | 
	
		
			
				|  |  | +            var nextSibling = nextSiblingID == -1 ? null : this.nodes[this.prefix + nextSiblingID];
 | 
	
		
			
				|  |  | +            let preInsertNode = null, nodes = [];
 | 
	
		
			
				|  |  | +            for (let d of datas) {
 | 
	
		
			
				|  |  | +                let node = new Node(this, d.data);
 | 
	
		
			
				|  |  | +                if (preInsertNode == null) {
 | 
	
		
			
				|  |  |                      if (nextSibling) {
 | 
	
		
			
				|  |  |                          tools.addNodes(this, parent, [node], nextSibling.siblingIndex());
 | 
	
		
			
				|  |  |                      } else {
 | 
	
		
			
				|  |  |                          tools.addNodes(this, parent, [node]);
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  | -                }else {
 | 
	
		
			
				|  |  | +                } else {
 | 
	
		
			
				|  |  |                      tools.addNodes(this, parent, [node], preInsertNode.siblingIndex());
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |                  this.nodes[this.prefix + d.data.ID] = node;
 | 
	
		
			
				|  |  | -                if(preInsertNode) node.setNextSibling(preInsertNode);
 | 
	
		
			
				|  |  | +                if (preInsertNode) node.setNextSibling(preInsertNode);
 | 
	
		
			
				|  |  |                  preInsertNode = node;
 | 
	
		
			
				|  |  |                  nodes.push(node);
 | 
	
		
			
				|  |  |              }
 | 
	
	
		
			
				|  | @@ -581,7 +581,7 @@ var idTree = {
 | 
	
		
			
				|  |  |          Tree.prototype.insertByID = function (newID, parentID, nextSiblingID) {
 | 
	
		
			
				|  |  |              var node = null, data = {};
 | 
	
		
			
				|  |  |              var parent = parentID == -1 ? null : this.nodes[this.prefix + parentID];
 | 
	
		
			
				|  |  | -            var nextSibling = nextSiblingID == -1 ? null: this.nodes[this.prefix + nextSiblingID];
 | 
	
		
			
				|  |  | +            var nextSibling = nextSiblingID == -1 ? null : this.nodes[this.prefix + nextSiblingID];
 | 
	
		
			
				|  |  |              if (newID) {
 | 
	
		
			
				|  |  |                  data = {};
 | 
	
		
			
				|  |  |                  data[this.setting.id] = newID;
 | 
	
	
		
			
				|  | @@ -602,9 +602,9 @@ var idTree = {
 | 
	
		
			
				|  |  |              var data = [];
 | 
	
		
			
				|  |  |              var newID = this.newNodeID();
 | 
	
		
			
				|  |  |              var parent = parentID == -1 ? null : this.nodes[this.prefix + parentID];
 | 
	
		
			
				|  |  | -            var nextSibling = nextSiblingID == -1 ? null: this.nodes[this.prefix + nextSiblingID];
 | 
	
		
			
				|  |  | +            var nextSibling = nextSiblingID == -1 ? null : this.nodes[this.prefix + nextSiblingID];
 | 
	
		
			
				|  |  |              if (newID !== -1) {
 | 
	
		
			
				|  |  | -                data.push({type: 'new', data: this.getDataTemplate(newID, parent ? parent.getID() : this.setting.rootId, nextSibling ? nextSibling.getID() : this.setting.rootId)});
 | 
	
		
			
				|  |  | +                data.push({ type: 'new', data: this.getDataTemplate(newID, parent ? parent.getID() : this.setting.rootId, nextSibling ? nextSibling.getID() : this.setting.rootId) });
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |                  if (nextSibling && nextSibling.preSibling) {
 | 
	
		
			
				|  |  |                      tools.addUpdateDataForNextSibling(data, nextSibling.preSibling, newID);
 | 
	
	
		
			
				|  | @@ -617,17 +617,17 @@ var idTree = {
 | 
	
		
			
				|  |  |              return data;
 | 
	
		
			
				|  |  |          };
 | 
	
		
			
				|  |  |          //插入多行
 | 
	
		
			
				|  |  | -        Tree.prototype.getInsertDatas = function (rowCount,parentID, nextSiblingID) {
 | 
	
		
			
				|  |  | -            let data = [],preInsertID = null,lastID;
 | 
	
		
			
				|  |  | +        Tree.prototype.getInsertDatas = function (rowCount, parentID, nextSiblingID) {
 | 
	
		
			
				|  |  | +            let data = [], preInsertID = null, lastID;
 | 
	
		
			
				|  |  |              let parent = parentID == -1 ? null : this.nodes[this.prefix + parentID];
 | 
	
		
			
				|  |  | -            let nextSibling = nextSiblingID == -1 ? null: this.nodes[this.prefix + nextSiblingID];
 | 
	
		
			
				|  |  | -            for(let i=0;i<rowCount ;i++){//先插入的在最后,后插的在最前
 | 
	
		
			
				|  |  | +            let nextSibling = nextSiblingID == -1 ? null : this.nodes[this.prefix + nextSiblingID];
 | 
	
		
			
				|  |  | +            for (let i = 0; i < rowCount; i++) {//先插入的在最后,后插的在最前
 | 
	
		
			
				|  |  |                  let newID = this.newNodeID();
 | 
	
		
			
				|  |  | -                if(newID !== -1){
 | 
	
		
			
				|  |  | -                    if(preInsertID == null){//说明是第一个插入的
 | 
	
		
			
				|  |  | -                        data.push({type: 'new', data: this.getDataTemplate(newID, parent ? parent.getID() : this.setting.rootId, nextSibling ? nextSibling.getID() : this.setting.rootId)});
 | 
	
		
			
				|  |  | -                    }else {//其它的下一节点ID取上一个插入的节点
 | 
	
		
			
				|  |  | -                        data.push({type: 'new', data: this.getDataTemplate(newID, parent ? parent.getID() : this.setting.rootId, preInsertID)});
 | 
	
		
			
				|  |  | +                if (newID !== -1) {
 | 
	
		
			
				|  |  | +                    if (preInsertID == null) {//说明是第一个插入的
 | 
	
		
			
				|  |  | +                        data.push({ type: 'new', data: this.getDataTemplate(newID, parent ? parent.getID() : this.setting.rootId, nextSibling ? nextSibling.getID() : this.setting.rootId) });
 | 
	
		
			
				|  |  | +                    } else {//其它的下一节点ID取上一个插入的节点
 | 
	
		
			
				|  |  | +                        data.push({ type: 'new', data: this.getDataTemplate(newID, parent ? parent.getID() : this.setting.rootId, preInsertID) });
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  |                      this.maxNodeID(newID);
 | 
	
		
			
				|  |  |                      preInsertID = newID;
 | 
	
	
		
			
				|  | @@ -656,25 +656,34 @@ var idTree = {
 | 
	
		
			
				|  |  |                  } else {
 | 
	
		
			
				|  |  |                      tools.addNodes(this, parent, [node]);
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | -                this.nodes[this.prefix +  data[this.setting.id]] = node;
 | 
	
		
			
				|  |  | +                this.nodes[this.prefix + data[this.setting.id]] = node;
 | 
	
		
			
				|  |  |                  tools.sortTreeItems(this);
 | 
	
		
			
				|  |  | -                this.maxNodeID( data[this.setting.id]);
 | 
	
		
			
				|  |  | +                this.maxNodeID(data[this.setting.id]);
 | 
	
		
			
				|  |  |                  return node;
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          };
 | 
	
		
			
				|  |  | +        // 插入离散节点
 | 
	
		
			
				|  |  | +        Tree.prototype.insertByDatas = function (datas) {
 | 
	
		
			
				|  |  | +            const nodes = [];
 | 
	
		
			
				|  |  | +            datas.forEach(item => {
 | 
	
		
			
				|  |  | +                const node = this.insertByData(item, item.ParentID, item.NextSiblingID);
 | 
	
		
			
				|  |  | +                nodes.push(node);
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +            return nodes;
 | 
	
		
			
				|  |  | +        };
 | 
	
		
			
				|  |  |          //批量新增节点到节点后项,节点已有树结构数据
 | 
	
		
			
				|  |  |          Tree.prototype.insertDatasTo = function (preData, datas) {
 | 
	
		
			
				|  |  |              let rst = [];
 | 
	
		
			
				|  |  | -            for(let data of datas){
 | 
	
		
			
				|  |  | +            for (let data of datas) {
 | 
	
		
			
				|  |  |                  this.nodes[this.prefix + data.ID] = new Node(this, data.ID);
 | 
	
		
			
				|  |  |                  this.nodes[this.prefix + data.ID]['data'] = data;
 | 
	
		
			
				|  |  |                  rst.push(this.nodes[this.prefix + data.ID]);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            for(let data of datas){
 | 
	
		
			
				|  |  | +            for (let data of datas) {
 | 
	
		
			
				|  |  |                  let node = this.nodes[this.prefix + data.ID];
 | 
	
		
			
				|  |  |                  let parent = data.ParentID == -1 ? null : this.nodes[this.prefix + data.ParentID];
 | 
	
		
			
				|  |  |                  node.parent = parent;
 | 
	
		
			
				|  |  | -                if(!parent){
 | 
	
		
			
				|  |  | +                if (!parent) {
 | 
	
		
			
				|  |  |                      this.roots.push(node);
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |                  else {
 | 
	
	
		
			
				|  | @@ -682,14 +691,14 @@ var idTree = {
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |                  let next = data.NextSiblingID == -1 ? null : this.nodes[this.prefix + data.NextSiblingID];
 | 
	
		
			
				|  |  |                  node.nextSibling = next;
 | 
	
		
			
				|  |  | -                if(next){
 | 
	
		
			
				|  |  | +                if (next) {
 | 
	
		
			
				|  |  |                      next.preSibling = node;
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              let preNode = this.nodes[this.prefix + preData.ID];
 | 
	
		
			
				|  |  | -            if(preNode){
 | 
	
		
			
				|  |  | +            if (preNode) {
 | 
	
		
			
				|  |  |                  preNode.nextSibling = this.nodes[this.prefix + preData.NextSiblingID] ? this.nodes[this.prefix + preData.NextSiblingID] : null;
 | 
	
		
			
				|  |  | -                if(preNode.nextSibling){
 | 
	
		
			
				|  |  | +                if (preNode.nextSibling) {
 | 
	
		
			
				|  |  |                      preNode.nextSibling.preSibling = preNode;
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              }
 | 
	
	
		
			
				|  | @@ -700,7 +709,7 @@ var idTree = {
 | 
	
		
			
				|  |  |          };
 | 
	
		
			
				|  |  |          Tree.prototype.delete = function (node) {
 | 
	
		
			
				|  |  |              var success = false, that = this;
 | 
	
		
			
				|  |  | -            if(node) success = that.m_delete([node]);
 | 
	
		
			
				|  |  | +            if (node) success = that.m_delete([node]);
 | 
	
		
			
				|  |  |              return success;
 | 
	
		
			
				|  |  |          };
 | 
	
		
			
				|  |  |          Tree.prototype.m_delete = function (nodes) {
 | 
	
	
		
			
				|  | @@ -711,7 +720,7 @@ var idTree = {
 | 
	
		
			
				|  |  |                      deleteIdIndex(node.children);
 | 
	
		
			
				|  |  |                  })
 | 
	
		
			
				|  |  |              };
 | 
	
		
			
				|  |  | -            for(let n of nodes){
 | 
	
		
			
				|  |  | +            for (let n of nodes) {
 | 
	
		
			
				|  |  |                  deleteIdIndex([n]);
 | 
	
		
			
				|  |  |                  if (n.preSibling) {
 | 
	
		
			
				|  |  |                      n.preSibling.setNextSibling(n.nextSibling);
 | 
	
	
		
			
				|  | @@ -734,76 +743,76 @@ var idTree = {
 | 
	
		
			
				|  |  |              let o_next = o_parent.nextSibling;//父节点的下一节点
 | 
	
		
			
				|  |  |              let o_pre = nodes[0].preSibling;
 | 
	
		
			
				|  |  |              let o_children = o_parent.children;//旧的所有兄弟节点
 | 
	
		
			
				|  |  | -            let children = o_parent.parent?o_parent.parent.children:this.roots;//新的兄弟节点
 | 
	
		
			
				|  |  | +            let children = o_parent.parent ? o_parent.parent.children : this.roots;//新的兄弟节点
 | 
	
		
			
				|  |  |              let last;
 | 
	
		
			
				|  |  |              let lastNext;//最后一个选中节点后面的所有兄弟节点变成最后一个节点的子节点
 | 
	
		
			
				|  |  | -            for(let i = 0; i<nodes.length;i++){
 | 
	
		
			
				|  |  | +            for (let i = 0; i < nodes.length; i++) {
 | 
	
		
			
				|  |  |                  let index = children.indexOf(o_parent) + 1;
 | 
	
		
			
				|  |  | -                children.splice(index + i,0,nodes[i]);//往新的父节点的子节点插入节点
 | 
	
		
			
				|  |  | +                children.splice(index + i, 0, nodes[i]);//往新的父节点的子节点插入节点
 | 
	
		
			
				|  |  |                  o_children.splice(nodes[i].siblingIndex(), 1);//旧的数组删除节点
 | 
	
		
			
				|  |  | -                if(i == 0){//第一个节点变成原来父节点的下一节点
 | 
	
		
			
				|  |  | +                if (i == 0) {//第一个节点变成原来父节点的下一节点
 | 
	
		
			
				|  |  |                      o_parent.setNextSibling(nodes[i]);
 | 
	
		
			
				|  |  | -                    if(o_pre) o_pre.setNextSibling(null); //第一个选中节点的前一节点的下一节点设置为空
 | 
	
		
			
				|  |  | +                    if (o_pre) o_pre.setNextSibling(null); //第一个选中节点的前一节点的下一节点设置为空
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |                  nodes[i].setParent(o_parent.parent);
 | 
	
		
			
				|  |  |                  last = nodes[i];
 | 
	
		
			
				|  |  |                  lastNext = last.nextSibling;
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              last.setNextSibling(o_next);//最后一个选中的节点的下一个节点设置为原父节点的下一节点
 | 
	
		
			
				|  |  | -            if(lastNext){
 | 
	
		
			
				|  |  | +            if (lastNext) {
 | 
	
		
			
				|  |  |                  let t_index = o_children.indexOf(lastNext);
 | 
	
		
			
				|  |  | -                for(let j = t_index;j <o_children.length;j++ ){//剩下的添加为最后一个选中节点的子节点
 | 
	
		
			
				|  |  | +                for (let j = t_index; j < o_children.length; j++) {//剩下的添加为最后一个选中节点的子节点
 | 
	
		
			
				|  |  |                      last.addChild(o_children[j]);
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | -                if(o_children.length > t_index)  o_children.splice(t_index, o_children.length - t_index);//从原先的children中移除
 | 
	
		
			
				|  |  | +                if (o_children.length > t_index) o_children.splice(t_index, o_children.length - t_index);//从原先的children中移除
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            if (o_parent.parent&& !o_parent.parent.expanded)  o_parent.parent.setExpanded(true);
 | 
	
		
			
				|  |  | +            if (o_parent.parent && !o_parent.parent.expanded) o_parent.parent.setExpanded(true);
 | 
	
		
			
				|  |  |              tools.sortTreeItems(this);
 | 
	
		
			
				|  |  |              return true;
 | 
	
		
			
				|  |  |          };
 | 
	
		
			
				|  |  |          Tree.prototype.getUpLevelDatas = function (nodes) {
 | 
	
		
			
				|  |  |              //getParentID
 | 
	
		
			
				|  |  | -            let o_parentID =  nodes[0].getParentID();
 | 
	
		
			
				|  |  | +            let o_parentID = nodes[0].getParentID();
 | 
	
		
			
				|  |  |              let o_children = nodes[0].parent.children;//旧的所有兄弟节点
 | 
	
		
			
				|  |  |              let o_pre = nodes[0].preSibling;
 | 
	
		
			
				|  |  |              let new_parentID = nodes[0].parent.getParentID();
 | 
	
		
			
				|  |  |              let o_nextID = nodes[0].parent.getNextSiblingID();
 | 
	
		
			
				|  |  | -            let dataMap = {},updateDatas=[],lastID,lastNext;
 | 
	
		
			
				|  |  | -            for(let i = 0; i<nodes.length;i++){
 | 
	
		
			
				|  |  | -                if(i == 0){
 | 
	
		
			
				|  |  | -                    dataMap[o_parentID] = {"ID":o_parentID,"NextSiblingID":nodes[i].getID()};
 | 
	
		
			
				|  |  | -                    if(o_pre) dataMap[o_pre.getID()] = {"ID":o_pre.getID(),"NextSiblingID":-1}; //nodes[i].preSibling.setNextSibling(null);
 | 
	
		
			
				|  |  | +            let dataMap = {}, updateDatas = [], lastID, lastNext;
 | 
	
		
			
				|  |  | +            for (let i = 0; i < nodes.length; i++) {
 | 
	
		
			
				|  |  | +                if (i == 0) {
 | 
	
		
			
				|  |  | +                    dataMap[o_parentID] = { "ID": o_parentID, "NextSiblingID": nodes[i].getID() };
 | 
	
		
			
				|  |  | +                    if (o_pre) dataMap[o_pre.getID()] = { "ID": o_pre.getID(), "NextSiblingID": -1 }; //nodes[i].preSibling.setNextSibling(null);
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | -                dataMap[nodes[i].getID()] = {"ID":nodes[i].getID(),"ParentID":new_parentID};
 | 
	
		
			
				|  |  | +                dataMap[nodes[i].getID()] = { "ID": nodes[i].getID(), "ParentID": new_parentID };
 | 
	
		
			
				|  |  |                  lastID = nodes[i].getID();
 | 
	
		
			
				|  |  |                  lastNext = nodes[i].nextSibling;
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            if(dataMap[lastID] !== undefined){
 | 
	
		
			
				|  |  | +            if (dataMap[lastID] !== undefined) {
 | 
	
		
			
				|  |  |                  dataMap[lastID].NextSiblingID = o_nextID;
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            if(lastNext){
 | 
	
		
			
				|  |  | +            if (lastNext) {
 | 
	
		
			
				|  |  |                  let t_index = o_children.indexOf(lastNext);
 | 
	
		
			
				|  |  | -                for(let j = t_index;j <o_children.length;j++ ){//剩下的添加为最后一个选中节点的子节点
 | 
	
		
			
				|  |  | -                    dataMap[o_children[j].getID()] = {"ID":o_children[j].getID(),"ParentID":lastID};
 | 
	
		
			
				|  |  | +                for (let j = t_index; j < o_children.length; j++) {//剩下的添加为最后一个选中节点的子节点
 | 
	
		
			
				|  |  | +                    dataMap[o_children[j].getID()] = { "ID": o_children[j].getID(), "ParentID": lastID };
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            for(let key in dataMap){
 | 
	
		
			
				|  |  | -                updateDatas.push({type: 'update', data:dataMap[key]});
 | 
	
		
			
				|  |  | +            for (let key in dataMap) {
 | 
	
		
			
				|  |  | +                updateDatas.push({ type: 'update', data: dataMap[key] });
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              return updateDatas;
 | 
	
		
			
				|  |  |          };
 | 
	
		
			
				|  |  |          Tree.prototype.m_downLevel = function (nodes) {
 | 
	
		
			
				|  |  | -            let pre = nodes[0].preSibling ; //第一个节点的前一节点,即会成为新的父节点
 | 
	
		
			
				|  |  | -            let next ;//最后一个节点的后一节点,会成为pre 的下一个节点
 | 
	
		
			
				|  |  | -            let last ;//选中的最后一个节点,nextSibling要设置为0
 | 
	
		
			
				|  |  | -            for( let n of nodes){
 | 
	
		
			
				|  |  | +            let pre = nodes[0].preSibling; //第一个节点的前一节点,即会成为新的父节点
 | 
	
		
			
				|  |  | +            let next;//最后一个节点的后一节点,会成为pre 的下一个节点
 | 
	
		
			
				|  |  | +            let last;//选中的最后一个节点,nextSibling要设置为0
 | 
	
		
			
				|  |  | +            for (let n of nodes) {
 | 
	
		
			
				|  |  |                  next = n.nextSibling;
 | 
	
		
			
				|  |  |                  last = n;
 | 
	
		
			
				|  |  | -                let  children = n.parent?n.parent.children:this.roots;
 | 
	
		
			
				|  |  | +                let children = n.parent ? n.parent.children : this.roots;
 | 
	
		
			
				|  |  |                  children.splice(n.siblingIndex(), 1);
 | 
	
		
			
				|  |  |                  pre.addChild(n);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            if (!pre.expanded)  pre.setExpanded(true);
 | 
	
		
			
				|  |  | +            if (!pre.expanded) pre.setExpanded(true);
 | 
	
		
			
				|  |  |              pre.setNextSibling(next);
 | 
	
		
			
				|  |  |              last.nextSibling = null;
 | 
	
		
			
				|  |  |              tools.sortTreeItems(this);
 | 
	
	
		
			
				|  | @@ -811,25 +820,25 @@ var idTree = {
 | 
	
		
			
				|  |  |          };
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          Tree.prototype.getDownLevelDatas = function (nodes) {
 | 
	
		
			
				|  |  | -            let dataMap = {},updateDatas=[],nextID,last;//注释同m_downLevel 方法
 | 
	
		
			
				|  |  | +            let dataMap = {}, updateDatas = [], nextID, last;//注释同m_downLevel 方法
 | 
	
		
			
				|  |  |              let newParent = nodes[0].preSibling;//{"type":"update","data":{"ID":3,"ParentID":-1,"NextSiblingID":5}}
 | 
	
		
			
				|  |  | -            let newPre = newParent.children && newParent.children.length > 0 ? newParent.children[newParent.children.length -1]:null;
 | 
	
		
			
				|  |  | -            if(newPre){ //如果新的父节点有子节点,则把新的父节点的最后一个子节点的下一节点的值改成第一个选中节点的ID
 | 
	
		
			
				|  |  | -                dataMap[newPre.getID()] = {"ID":newPre.getID(),"NextSiblingID":nodes[0].getID()}
 | 
	
		
			
				|  |  | +            let newPre = newParent.children && newParent.children.length > 0 ? newParent.children[newParent.children.length - 1] : null;
 | 
	
		
			
				|  |  | +            if (newPre) { //如果新的父节点有子节点,则把新的父节点的最后一个子节点的下一节点的值改成第一个选中节点的ID
 | 
	
		
			
				|  |  | +                dataMap[newPre.getID()] = { "ID": newPre.getID(), "NextSiblingID": nodes[0].getID() }
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            for(let n of nodes){
 | 
	
		
			
				|  |  | +            for (let n of nodes) {
 | 
	
		
			
				|  |  |                  nextID = n.getNextSiblingID();
 | 
	
		
			
				|  |  |                  last = n;
 | 
	
		
			
				|  |  | -                dataMap[n.getID()] = {"ID":n.getID(),"ParentID":newParent.getID()}//修改父ID;
 | 
	
		
			
				|  |  | +                dataMap[n.getID()] = { "ID": n.getID(), "ParentID": newParent.getID() }//修改父ID;
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            dataMap[newParent.getID()] = {"ID":newParent.getID(),"NextSiblingID":nextID}//设置新的父节点的下一个节点ID;
 | 
	
		
			
				|  |  | -            if(dataMap[last.getID()]!==undefined){//把最后一个节点的下一个节点ID变成-1
 | 
	
		
			
				|  |  | +            dataMap[newParent.getID()] = { "ID": newParent.getID(), "NextSiblingID": nextID }//设置新的父节点的下一个节点ID;
 | 
	
		
			
				|  |  | +            if (dataMap[last.getID()] !== undefined) {//把最后一个节点的下一个节点ID变成-1
 | 
	
		
			
				|  |  |                  dataMap[last.getID()].NextSiblingID = -1
 | 
	
		
			
				|  |  | -            }else {
 | 
	
		
			
				|  |  | -                dataMap[last.getID()] = {"ID":last.getID(),"NextSiblingID":-1};
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                dataMap[last.getID()] = { "ID": last.getID(), "NextSiblingID": -1 };
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            for(let key in dataMap){
 | 
	
		
			
				|  |  | -                updateDatas.push({type: 'update', data:dataMap[key]});
 | 
	
		
			
				|  |  | +            for (let key in dataMap) {
 | 
	
		
			
				|  |  | +                updateDatas.push({ type: 'update', data: dataMap[key] });
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              return updateDatas;
 | 
	
		
			
				|  |  |          };
 | 
	
	
		
			
				|  | @@ -840,7 +849,7 @@ var idTree = {
 | 
	
		
			
				|  |  |                  nodes.forEach(function (node) {
 | 
	
		
			
				|  |  |                      var delData = {};
 | 
	
		
			
				|  |  |                      delData[node.tree.setting.id] = node.getID();
 | 
	
		
			
				|  |  | -                    datas.push({type: 'delete', data: delData});
 | 
	
		
			
				|  |  | +                    datas.push({ type: 'delete', data: delData });
 | 
	
		
			
				|  |  |                      addUpdateDataForDelete(datas, node.children);
 | 
	
		
			
				|  |  |                  })
 | 
	
		
			
				|  |  |              };
 | 
	
	
		
			
				|  | @@ -852,32 +861,32 @@ var idTree = {
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              return data;
 | 
	
		
			
				|  |  |          };
 | 
	
		
			
				|  |  | -        Tree.prototype.getDeleteDatas = function (deleteMap,deleteNodes){//批量删除
 | 
	
		
			
				|  |  | +        Tree.prototype.getDeleteDatas = function (deleteMap, deleteNodes) {//批量删除
 | 
	
		
			
				|  |  |              let datas = [];
 | 
	
		
			
				|  |  | -            addDeleteDatas(datas,deleteNodes);
 | 
	
		
			
				|  |  | -            for(let d of deleteNodes){
 | 
	
		
			
				|  |  | -                addPreUpdateData(datas,deleteMap,d.preSibling,d.nextSibling);
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -           function addPreUpdateData(updateDatas,map,preSibling,nextSibling) {
 | 
	
		
			
				|  |  | -               if(preSibling && (map[preSibling.getID()] == undefined || map[preSibling.getID()] == null)){
 | 
	
		
			
				|  |  | -                   if(nextSibling){
 | 
	
		
			
				|  |  | -                      if(map[nextSibling.getID()]){//如果下一个节点也是要删除的,则再往下顺延
 | 
	
		
			
				|  |  | -                          addPreUpdateData(updateDatas,map,preSibling,nextSibling.nextSibling);
 | 
	
		
			
				|  |  | -                      }else {
 | 
	
		
			
				|  |  | -                          updateDatas.push({type: 'update', data: preSibling.tree.getDataTemplate(preSibling.getID(), preSibling.getParentID(),nextSibling.getID())});
 | 
	
		
			
				|  |  | -                      }
 | 
	
		
			
				|  |  | -                   }else {
 | 
	
		
			
				|  |  | -                       updateDatas.push({type: 'update', data: preSibling.tree.getDataTemplate(preSibling.getID(), preSibling.getParentID(),-1)});
 | 
	
		
			
				|  |  | -                   }
 | 
	
		
			
				|  |  | -               }
 | 
	
		
			
				|  |  | -           }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            function addDeleteDatas(dataArray,nodes) {
 | 
	
		
			
				|  |  | -                for(let n of nodes){
 | 
	
		
			
				|  |  | +            addDeleteDatas(datas, deleteNodes);
 | 
	
		
			
				|  |  | +            for (let d of deleteNodes) {
 | 
	
		
			
				|  |  | +                addPreUpdateData(datas, deleteMap, d.preSibling, d.nextSibling);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            function addPreUpdateData(updateDatas, map, preSibling, nextSibling) {
 | 
	
		
			
				|  |  | +                if (preSibling && (map[preSibling.getID()] == undefined || map[preSibling.getID()] == null)) {
 | 
	
		
			
				|  |  | +                    if (nextSibling) {
 | 
	
		
			
				|  |  | +                        if (map[nextSibling.getID()]) {//如果下一个节点也是要删除的,则再往下顺延
 | 
	
		
			
				|  |  | +                            addPreUpdateData(updateDatas, map, preSibling, nextSibling.nextSibling);
 | 
	
		
			
				|  |  | +                        } else {
 | 
	
		
			
				|  |  | +                            updateDatas.push({ type: 'update', data: preSibling.tree.getDataTemplate(preSibling.getID(), preSibling.getParentID(), nextSibling.getID()) });
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                    } else {
 | 
	
		
			
				|  |  | +                        updateDatas.push({ type: 'update', data: preSibling.tree.getDataTemplate(preSibling.getID(), preSibling.getParentID(), -1) });
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            function addDeleteDatas(dataArray, nodes) {
 | 
	
		
			
				|  |  | +                for (let n of nodes) {
 | 
	
		
			
				|  |  |                      let delData = {};
 | 
	
		
			
				|  |  |                      delData[n.tree.setting.id] = n.getID();
 | 
	
		
			
				|  |  | -                    dataArray.push({type: 'delete', data: delData});
 | 
	
		
			
				|  |  | -                    addDeleteDatas(dataArray,n.children);
 | 
	
		
			
				|  |  | +                    dataArray.push({ type: 'delete', data: delData });
 | 
	
		
			
				|  |  | +                    addDeleteDatas(dataArray, n.children);
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              return datas;
 | 
	
	
		
			
				|  | @@ -899,7 +908,25 @@ var idTree = {
 | 
	
		
			
				|  |  |              this.event[eventName] = eventFun;
 | 
	
		
			
				|  |  |          };
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +        Tree.prototype.resetID = function (items, IDFunc) {
 | 
	
		
			
				|  |  | +            const IDMap = {};
 | 
	
		
			
				|  |  | +            items.forEach(item => {
 | 
	
		
			
				|  |  | +                IDMap[item.ID] = IDFunc();
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +            items.forEach(item => {
 | 
	
		
			
				|  |  | +                if (IDMap[item.ID]) {
 | 
	
		
			
				|  |  | +                    item.ID = IDMap[item.ID];
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                if (IDMap[item.ParentID]) {
 | 
	
		
			
				|  |  | +                    item.ParentID = IDMap[item.ParentID];
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                if (IDMap[item.NextSiblingID]) {
 | 
	
		
			
				|  |  | +                    item.NextSiblingID = IDMap[item.NextSiblingID];
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +        };
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          return new Tree(setting);
 | 
	
		
			
				|  |  |      },
 | 
	
		
			
				|  |  | -    updateType: {update: 'update', new: 'new', delete: 'delete'}
 | 
	
		
			
				|  |  | +    updateType: { update: 'update', new: 'new', delete: 'delete' }
 | 
	
		
			
				|  |  |  };
 |