1. 程式人生 > >EXT 中tree中節點的上移與下移

EXT 中tree中節點的上移與下移

右鍵時,可以得到相關的節點
var preNode,curNode,nextNode;
function rightClickFn(panel2Tree, record, item, index, e) {
		e.preventDefault();
		e.stopEvent();
		curNode=record;
		preNode=curNode.previousSibling;
		nextNode=curNode.nextSibling;
		groupid=record.get('groupid');
		groupname=record.get('text');
		pgroupid=record.get('pgroupid');
		//alert(record.get('groupid'));//這是得到模型中的值
		if(record.isLeaf()){//這是人員的管理
			rightClick2.showAt(e.getXY());
		}else{
			rightClick.showAt(e.getXY());//這是部門管理
		};				
}

然後就是根據Ajax來排序提交資料

if(preNode==null){
								  	  Ext.example.msg('訊息',"部門已經是排在最前面,要改變父節點,請選擇修改部門");
								  }else{
									  Ext.Ajax.request({
														url: 'control/group.php?act=move&id1='+encodeURI(preNode.get('groupid'))+'&disorder1='+encodeURI(preNode.get('disorder'))+'&id2='+encodeURI(curNode.get('groupid'))+'&disorder2='+encodeURI(curNode.get('disorder')),
														timeout: 10000,
														success: function(response){
															var preorder=preNode.get('disorder');
															var curorder=curNode.get('disorder');
														        curNode.set('disorder',preorder);
															preNode.set('disorder',curorder);
															curNode.commit();
															preNode.commit();
curNode.parentNode.insertBefore(curNode,preNode); //Ext.example.msg('訊息',response.responseText); }, failure:function(response){ Ext.example.msg('訊息',response.responseText); //Ext.MessageBox.alert("刪除失敗",response.responseText); } }); } //previousSibling(); //setMenu('policyapply.php?groupid='+encodeURI(groupid)+'&groupname='+encodeURI(groupname)+'&type=group'); }

 if(nextNode==null){
								  	  Ext.example.msg('訊息',"部門已經是排在最後面,要改變父節點,請選擇修改部門");
								  }else{
									 Ext.Ajax.request({//傳送ajax 刪除資料
														url: 'control/group.php?act=move&id1='+encodeURI(nextNode.get('groupid'))+'&disorder1='+encodeURI(nextNode.get('disorder'))+'&id2='+encodeURI(curNode.get('groupid'))+'&disorder2='+encodeURI(curNode.get('disorder')),
														timeout: 10000,
														success: function(response){
															var nextorder=nextNode.get('disorder');
															var curorder=curNode.get('disorder');
															curNode.set('disorder', nextorder);
															nextNode.set('disorder',curorder);
															curNode.commit();
															nextNode.commit();
															curNode.parentNode.insertBefore(curNode,nextNode.nextSibling);
															//Ext.example.msg('訊息',response.responseText);
														},
														failure:function(response){
															Ext.example.msg('訊息',response.responseText);
															//Ext.MessageBox.alert("刪除失敗",response.responseText);
														}
													});	
								  }
								   //setMenu('policyapply.php?groupid='+encodeURI(groupid)+'&groupname='+encodeURI(groupname)+'&type=group');
							  }