var mainNode;
var fileListTreeRoot = new Ext.tree.AsyncTreeNode({
id: '-1', text:'主目录', loader: new Ext.tree.TreeLoader({ url: '../../Data/FlawMould/FileListTree.aspx', listeners: { 'beforeload': function (treeloader, node) { treeloader.baseParams = { id: node.id, value: node.attributes.value, parentCode: node.attributes.parentCode, text: node.attributes.text, method: 'POST' }; } } })});//右键菜单var contextMenu1 = new Ext.menu.Menu({ items: [ { text: '新建单位', handler: add_node }, { text: '查看单位', handler: show_node }, { text: '删除单位', handler: del_node } ]});
//图标资料展示树
var fileListTree = new Ext.tree.TreePanel({ enableDD: true, animate: true, useArrows: true, root: fileListTreeRoot, rootVisible: true, border: false, lines: true, containerScroll: true, listeners: {//节点单击事件监听
"click": function (node, event) { alert(); }, "contextmenu": function (node, event) { mainNode = node; if (node.getDepth() == 0) { //根据需要设置右击菜单显示项 contextMenu1.items.items[0].show(); contextMenu1.items.items[1].hide(); contextMenu1.items.items[2].hide(); } else { } contextMenu1.showAt(event.getXY(node)); } }//listerns over});//把treePanel放到panel里
var treePanel =new Ext.Panel({
//自动收缩按钮 //添加split,设置最大、最小范围 split: true, minSize: 100, maxSize: 300, region: 'east', //collapsible: true, border: false, width: 200, layout: "accordion", //extraCls: "roomtypegridbbar", //添加动画效果 layoutConfig: { animate: true }, region: "east", // items: [{ title: "<b>文件目录</b>", autoScroll: true, items: [fileListTree] }]});//右击添加新目录
add_node = function () {
//添加节点panel var NodePanel = new Ext.form.FormPanel({ width: 410, height: 110, plain: true, layout: "form", defaultType: "textfield", labelWidth: 90, fileUpload: true, baseCls: "x-plain", //锚点布局 defaults: { anchor: "95%", msgTarget: "side" }, buttonAlign: "center", bodyStyle: "padding:0 0 0 0", items: [{ name: "folderName", fieldLabel: "文件夹名称", allowBlank: false, blankText: "文件夹名称不允许为空" }] }); //添加节点窗口 var nodePanelWin = new Ext.Window({ title: "文件夹信息", width: 450, height: 130, //autoScroll:true, plain: true, //iconCls:"addicon", //不可以随意改变大小 resizable: false, //是否可以拖动 //draggable:false, defaultType: "textfield", labelWidth: 100, collapsible: true, //允许缩放条 closeAction: 'hide', closable: true, plain: true, //弹出模态窗体 modal: 'true', buttonAlign: "center", bodyStyle: "padding:10px 0 0 15px", items: [NodePanel], listeners: { "show": function () { //当window show事件发生时清空一下表单 NodePanel.getForm().reset(); } }, buttons: [{ text: "保存信息", minWidth: 70, handler: function () { //右击的文件夹的id var currentID = mainNode; if (NodePanel.getForm().isValid()) { //弹出效果 Ext.MessageBox.show ( { msg: '正在保存,请稍等...', progressText: 'Saving...', width: 300, wait: true, waitConfig: { interval: 200 }, icon: 'download', animEl: 'saving' } ); // setTimeout(function(){Ext.MessageBox.hide(); // }, 1000); NodePanel.form.submit({ url: "../../Data/FlawMould/FolderTreeEdit/AddFolder.aspx?currentID=" + mainNode.attributes['id'], method: "POST", success: function (form, action) { //成功后 var flag = action.result.success; if(flag=="true") { Ext.MessageBox.alert("恭喜","信息保存成功!"); nodePanelWin.hide(); fileListTreeRoot.reload(); fileListTree.expandAll(); } else { var message=action.result.error Ext.MessageBox.alert("提示",message); } }, failure: function (form, action) { var flag = action.result.success; alert(flag); Ext.MessageBox.alert("提示!", "保存信息失败!"); } }); } } }, { text: "重置", minWidth: 70, qtip: "重置数据", handler: function () { NodePanel.getForm().reset(); } }, { text: "取 消", minWidth: 70, handler: function () { nodePanelWin.hide(); } }] }); //nodePanelWin over nodePanelWin.show();}---------aspx的后台代码----------
public partial class Data_FlawMould_FolderTree : System.Web.UI.Page
{ protected void Page_Load(object sender, EventArgs e) { getTree(); } class TreeType { public string id; public string parentId; public string text; public string value; public string iconCls; public string href; public bool leaf; public int number; public string type; public string parentCode; public string icon; } public void getTree() { string id = Request.Form["id"]; flawMould.BLL.T_FolderTree fBll= new flawMould.BLL.T_FolderTree(); List<flawMould.Model.T_FolderTree> fModelList = fBll.GetModelList("parent='"+ id +"'"); // List<TreeType> treeList = new List<TreeType>(); DTreeJSONHelper json = new DTreeJSONHelper(); json.success = true; TreeType t = new TreeType(); for (int i = 0; i < fModelList.Count; i++) { t.id = fModelList[i].id; t.parentId = fModelList[i].parent; t.text = fModelList[i].name; t.value = fBll.GetModelList("parent='" + t.id + "'").Count > 0 ? "0" : "1"; //treeList.Add(t); json.AddItem("id", t.id); json.AddItem("parentId", t.parentId); json.AddItem("text", t.text); json.AddItem("leaf", t.value); json.ItemOk(); } string jsonStr = Newtonsoft.Json.JsonConvert.SerializeObject(treeList); Response.Write( json.ToString() ); } }