首页 > 代码库 > ExtJs treepanel和TabPanel配合使用

ExtJs treepanel和TabPanel配合使用

tree.js

Ext.onReady(function() {
			Ext.lib.Ajax.defaultPostHeader += '; charset=utf-8';
			var center = new Ext.TabPanel(
					{
						id : 'tab_main',
						region : 'center',
						frame : false,
						items : [ {
							id : 'welcome',
							title : '首页',
							html : "<iframe src=http://www.mamicode.com/'welcome.jsp' width='100%' height='100%' frameboder='0' srcolling='auto''/>">
index.html

<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css"
	href=http://www.mamicode.com/"ext/resources/css/ext-all.css" />>TreeAction.java

package com.lin.action;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

public class TreeAction extends ActionSupport {
	private String node;

	public String getNode() {
		return node;
	}

	public void setNode(String node) {
		this.node = node;
	}

	@Override
	public String execute() throws Exception {
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setContentType("text/json; charset=utf-8");
		PrintWriter pw = response.getWriter();
		System.out.println(node);
		if ("root".equals(node)) {
			pw.append("[{id:'module1',text:'模块1',leaf:false},{id:'module2',text:'模块2',leaf:true,url:'module2.jsp'}]");
		} else {
			pw.append("[{id:'module3',text:'模块3',leaf:true,url:'module3.jsp'}]");
		}
		pw.flush();
		pw.close();
		return NONE;
	}
}


实现效果: