EXT4 동적 트리

7301 단어 ext4
EXT JS4.0 트리의 생성과 마운트는 EXT3.0에 비해 비교적 큰 변화를 일으켰다. 차원이 비교적 뚜렷하다. 먼저 TreeStore를 마운트한 다음에 TreePanel을 마운트하고 TreeStore의 값을 TreePanel에 전달한다.그러나 이런 로딩 방식은 Ext Js3.0의 로딩 방식이 유연하지 않고 감청해도 그다지 편리하지 않다.초기에 백그라운드에서 값을 전달하고 동적 트리를 생성하는 기능을 하였으니 참고하시기 바랍니다.
 
프런트엔드 js 코드:
 
 
// 
function createXxTrees(){
	
	var xxMenuArr = [{
				text: "XXX ",
				expanded: false,
				iconCls:"leftMenuIcon",
				icon:"images/node/utcs/folder.jpg",
				children: [{
					text: " ",
					iconCls:"leftMenuIcon",
					icon:"images/node/utcs/bianji.png",
					leaf: true
				},{
					text: " ",
					iconCls:"leftMenuIcon",
					icon:"images/node/utcs/bianji.png",
					leaf: true
				},{
					text: " ",
					iconCls:"leftMenuIcon",
					icon:"images/node/utcs/bianji.png",
					leaf: true
				}
				]
			}
			];
	
	// 
	Ext.Ajax.request({
		url : 'XxTreeAction.action',
		//params : {},
		success : function(response,returnValue)
		{
			
			var info = Ext.JSON.decode(response.responseText);
			var nodes = info.nodes;
			if(info.success){
				var nodeRoot = {
					text:" ",
			        expanded: true,
					iconCls:"leftMenuIcon",
					icon:"images/node/utcs/folder.jpg",
			        children: nodes
			    }
				 xxMenuArr.push(nodeRoot);
			}
						
		},
		failure : function(response)
		{
    		
		},
		async: false   
	});
	
	
	xxTreeStore = Ext.create('Ext.data.TreeStore', {
		root: {
			expanded: true,
			children: xxMenuArr
		}
	});
	// 
if (Ext.getCmp(' xxTreePanel ') == null ) {
		Ext.create('Ext.tree.Panel', {
			id: 'xxTreePanel',
			width: leftMenuWidth,
			height: leftMenuHeight,
			store:  xxTreeStore ,
			rootVisible: false,
			renderTo: "xxDivId",//HTML DIV Id
			listeners: {
				itemclick: function(view, record, element, index){

																			
				}
			}
		});
	}
			
}


	
 
 
백그라운드 XxTreeAction 실행 방법 코드:
 
 
 
	public String execute() throws Exception
	{
		List<TreeNode> serverTreeList = new ArrayList<TreeNode>();// 
		List<TreeNode> childrenTreeList = new ArrayList<TreeNode>();
		try {

			List<KkServerInfo> serverInfoList = serverService.findAll();

			// 
			for(int i=0;i<serverInfoList.size();i++){
				KkServerInfo serverInfo = serverInfoList.get(i);
				long serverId = serverInfo.getId();
				// 
				TreeNode serverTreeNode = new TreeNode();
				serverTreeNode.setText(serverInfo.getKkServerName());
				serverTreeNode.setId("s#"+serverInfo.getId());
				serverTreeNode.setCls("");
				serverTreeNode.setIconCls("leftMenuIcon");
				serverTreeNode.setIcon("images/node/utcs/server.jpg");
				serverTreeNode.setExpanded(true);
				// 
				List<TreeNode> areaTreaNodeList =  new ArrayList<TreeNode>();
				
				List<KkDomain> areaInfoList = areaService.selectKkAreaListByServerId(serverId);
				// 
				for(int j=0;j<areaInfoList.size();j++){
					KkDomain areaInfo  = areaInfoList.get(j);
					long areaId = areaInfo.getId();
					// 
					TreeNode areaTreeNode = new TreeNode();
					areaTreeNode.setText(areaInfo.getName());
					areaTreeNode.setId("a#"+areaInfo.getId());
					areaTreeNode.setCls("");
					areaTreeNode.setIconCls("leftMenuIcon");
					areaTreeNode.setIcon("images/node/utcs/yu.jpg");
					areaTreeNode.setExpanded(false);

					// 
					List<TreeNode> nodeTreeNodeList =  new ArrayList<TreeNode>();
					List<KkInfo> nodeInfoList = nodeService.selectKkInfoListByAreaId(areaId);
					
					// 
					for(int m=0;m<nodeInfoList.size();m++){
						KkInfo nodeInfo  = nodeInfoList.get(m);
						// 
						TreeNode nodeTreeNode = new TreeNode();
						nodeTreeNode.setText(nodeInfo.getAddress());
						nodeTreeNode.setId("n#"+nodeInfo.getId());
						nodeTreeNode.setCls("");
						nodeTreeNode.setLeaf(true);
						nodeTreeNode.setIconCls("leftMenuIcon");
						nodeTreeNode.setIcon("images/node/kkcs/kkcs.png");

						nodeTreeNode.setChildren(childrenTreeList);

						nodeTreeNodeList.add(nodeTreeNode);

					}//end  

					
					areaTreeNode.setChildren(nodeTreeNodeList);
					areaTreaNodeList.add(areaTreeNode);// 

				}//end   
				serverTreeNode.setChildren(areaTreaNodeList);
				serverTreeList.add(serverTreeNode);
			}//end  
			
			success = true;	
			
		} catch (Exception e) {
			e.printStackTrace();
			success = false;	
		}
			
		this.nodes = serverTreeList;
		return SUCCESS;
	}
 
 
NodeTree.java 클래스: (TreeStore에서 트리 노드의 속성이 봉인됨)
 
 
 
import java.util.List;
/**
 *  
 * @author  
 *
 */
public class TreeNode {

	private String text;
	private String id;
	private String cls;
	private boolean expanded; 
	private String iconCls;
	private String icon;
	private String href;
	private boolean leaf;
	private List<TreeNode> children;
	
	public String getIcon() {
		return icon;
	}
	public void setIcon(String icon) {
		this.icon = icon;
	}
	public String getHref() {
		return href;
	}
	public String getIconCls() {
		return iconCls;
	}
	public void setIconCls(String iconCls) {
		this.iconCls = iconCls;
	}
	public void setHref(String href) {
		this.href = href;
	}
	public boolean isLeaf() {
		return leaf;
	}
	public void setLeaf(boolean leaf) {
		this.leaf = leaf;
	}
	public List<TreeNode> getChildren() {
		return children;
	}
	public void setChildren(List<TreeNode> children) {
		this.children = children;
	}
	public boolean isExpanded() {
		return expanded;
	}
	public void setExpanded(boolean expanded) {
		this.expanded = expanded;
	}

	public String getText() {
		return text;
	}
	public void setText(String text) {
		this.text = text;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getCls() {
		return cls;
	}
	public void setCls(String cls) {
		this.cls = cls;
	}
	
}

좋은 웹페이지 즐겨찾기