主页面前台代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MainForm.aspx.cs" Inherits="WebEXT.MainForm" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>管理系统</title>
</head>
<script type="text/javascript">
var addTab = function (tabPanel, id, url, title) {
var tab = tabPanel.getComponent(id);
var url = url.replace('#','');
if (!tab) {
tab = tabPanel.add({
id: id,
title: title,
closable: true,
autoLoad: {
showMask: true,
url: url,
mode: "iframe",
maskMsg: "Loading " + url + "..."
}
});
} tabPanel.setActiveTab(tab);
}
</script>
<body>
<form id="form1" runat="server">
<div>
<ext:ResourceManager ID="ResourceManager1" runat="server">
</ext:ResourceManager>
<ext:Viewport ID="Viewport" runat="server" Layout="BorderLayout">
<Items>
<ext:TreePanel runat="server" ID="TreePanel1" Region="West" MinWidth="" Width=""
Title="系统功能目录" Split="true" Border="true">
<Root>
<ext:Node Text="菜单" NodeID="-1" Expanded="True" Icon="ApplicationLink">
</ext:Node>
</Root>
<BottomBar><ext:StatusBar ID="StatusBar1" runat="server" AutoClear=""></ext:StatusBar></BottomBar>
<Store>
<ext:TreeStore runat="server">
<Proxy>
<ext:AjaxProxy Url="/tree-handler.ashx">
</ext:AjaxProxy>
</Proxy>
</ext:TreeStore>
</Store>
<Listeners>
<ItemClick Handler="addTab(#{TabPanel1},'tab'+record.data.id, record.data.href,record.data.text);">
</ItemClick>
</Listeners>
</ext:TreePanel>
<ext:TabPanel ID="TabPanel1" runat="server" Region="Center" ActiveTabIndex="" Border="True"
Title="主界面" AutoScroll="True">
<Items>
<ext:Panel ID="Test1" runat="server" Title="主页" Collapsed="false">
</ext:Panel>
</Items>
</ext:TabPanel>
</Items>
</ext:Viewport>
</div>
</form>
</body>
</html>
异步加载树的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Ext.Net; namespace WebEXT
{
/// <summary>
/// tree_handler 的摘要说明
/// </summary>
public class tree_handler : IHttpHandler
{ public void ProcessRequest(HttpContext context)
{
//得到node id
string nodeId = context.Request["node"]; SysMenuInfo sysMenuInfo = new SysMenuInfo();
//根据node id 进行处理
NodeCollection nodes = new NodeCollection();
IList<sysMenu> list = new List<sysMenu>();
list = sysMenuInfo.GetChildMenu(nodeId);
foreach (var sysMenu in list)
{
nodes.Add(new Node() { Text = sysMenu.nvcMenuName, Icon = Icon.ApplicationLink, Href = "#"+sysMenu.nvcUrl,NodeID=sysMenu.nvcID});
}
string responseString = nodes.ToJson();
context.Response.Write(responseString);
context.Response.End();
} public bool IsReusable
{
get
{
return false;
}
}
}
}