zoukankan      html  css  js  c++  java
  • Extjs4.x Ext.tree.Panel基本树控件的使用案例、源码

    1.Model

    Ext.define('WMS.model.VPTree', {
        extend: 'Ext.data.Model',
        fields: [
            { name: 'url', type: 'string' },
            { name: 'text', type: 'string' },
            { name: 'key', type: 'string' }
        ]
    });

    2.Store

    /// <reference path="http://www.cnblogs.com/Ext.js" />
    Ext.define("WMS.store.VPTreeMenu", {
        extend: 'Ext.data.TreeStore',
        autoLoad: true,
        model: 'WMS.model.VPTree',
        root: {
            text: '功能节点',
            id: 'root',
            expanded: true
        },
        proxy: {
            type: 'ajax',
            api: {
                read: '/Admin/Main/GetMenu'
            },
            reader: {
                type: 'json'
            }
        }
    });

    3.View

    Ext.define("WMS.view.Tree", {
        extend: 'Ext.tree.Panel',
        alias: 'widget.wmsTree',
        title: "功能导航",
        margins: '0 0 0 3',
         200,
        region: 'west',
        animate: true,
        store: 'VPTreeMenu',
        autoScroll: true,
        rootVisible: false,
        loadMsg:true,
        collapsible: true,//是否可以折叠
        split: true
    });

    4.后台构造json

    /// <summary>
            /// 获取系统的模块
            /// </summary>
            /// <returns></returns>
            public string GetMenuModule()
            {
                //根据用户获取所有的角色
                //根据角色获取所有的功能
                //根据SystemId构造树
                List<WMS_Module> Module = dal.GetMenu(AuthToken.CurrentUser.Id.ToString()).ToList();
                List<WMS_Module> fatherList = Module.FindAll(c => c.ParentId == AuthToken.SystemGuid).OrderBy(c => c.ModuleIndex).ToList();
                List<WMS_Module> childList = Module.FindAll(c => c.ParentId != AuthToken.SystemGuid).OrderBy(c => c.ModuleIndex).ToList();
                return "[" + CreateMenuTree(fatherList, childList).ToString().TrimEnd(',') + "]";
            }
    
            //递归
            private StringBuilder CreateMenuTree(List<WMS_Module> fatherList, List<WMS_Module> childList)
            {
                StringBuilder sb = new StringBuilder();
                foreach (WMS_Module menu in fatherList)
                {
                    StringBuilder sub = new StringBuilder();
                    //核心
                    string guid = menu.Id.ToString("D").ToUpper();
                    List<WMS_Module> stack = childList.FindAll(c => c.ParentId == guid).OrderBy(c => c.ModuleIndex).ToList();
                    if (stack.Count > 0) //说明是父节点
                    {
                        sub.Append("{text:'" + menu.ModuleName + "',expanded:true,id:'" + menu.Id.ToString() + "',children: [");
                        sub.Append(CreateMenuTree(stack, childList).ToString().TrimEnd(',') + "]},");
                    }
                    else //说明是子节点
                    {
                        sub.Append("{text:'" + menu.ModuleName + "',url:'" + menu.ModuleUrl + "',key:'"+menu.ModuleKey+"',leaf:true,iconCls:'" + menu.ModuleIcon + "',id:'" + menu.Id.ToString() + "'},");
                    }
                    sb.Append(sub);
                }
                return sb;
            }
  • 相关阅读:
    (转)使用 PyInstaller 把python程序 .py转为 .exe 可执行程序
    (转)使用 python Matplotlib 库绘图
    使用Matplotlib画图系列(一)
    Numpy常用金融计算(一)
    Windows中安装Linux子系统的详细步骤
    Centos7+Postfix+Dovecot实现内网邮件收发 风行天下
    centos7系统防火墙端口转发 风行天下
    Centos7+Postfix+Dovecot实现内网邮件收发
    centos7的路径含有空格Linux命令使用时路径存在空格、特殊符号(如、@等等) 风行天下
    zabbix无法使用Detect operating system [zabbix] 风行天下
  • 原文地址:https://www.cnblogs.com/qidian10/p/3060390.html
Copyright © 2011-2022 走看看