当前位置:  编程技术>.net/c#/asp.net

EasyUI Tree+Asp.net实现权限树或目录树导航的简单实例

    来源: 互联网  发布时间:2014-08-25

    本文导语:  代码如下:             网站后台通用管理系统,,您好!                                                $(function () {            $('#lefttree').tree({                animate: true,            ...

代码如下:


   
   
    网站后台通用管理系统,,您好!
   
   
   
   
   
   
   
   
   
   
        $(function () {
            $('#lefttree').tree({
                animate: true,
                checkbox: false,
                url: 'GetTreeDataFromDB.ashx?father=0',
                onClick: function (node) {
                    if (node.attributes != "") {
                        addTab(node.text, node.attributes, node.id);
                    }
                },
                onLoadSuccess: function (node, data) {
                    $('#lefttree').show();
                }
            });

            $('#loginOut').click(function () {
                $.messager.confirm('系统提示', '您确定要退出本次登录吗?', function (r) {
                    if (r) {
                        location.href = 'LoginExit.ashx';
                    }
                });
            })
        });
   
   
   
   
     
     

抱歉,请开启脚本支持!

     
     

       
       
         
       

        网站后台通用管理系统 V1.0

     

       
     

     

       
     

     

       

         
欢迎进入系统

       

     

     

       
刷新

       
       
关闭

       
全部关闭

       
除此之外全部关闭

       
       
当前页右侧全部关闭

       
当前页左侧全部关闭

       
       
退出

     

   



代码如下:

using System;
using System.Web;
using System.Configuration;
using System.Data;
using System.Text;
using System.Collections.Generic;
//add
using System.Web.Script.Serialization;

public class GetTreeDataFromDB : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";

        //获取数据库中的分类数据
        string fatherid = context.Request.QueryString["father"];
        DataTable dt = createDT();

        string json = GetTreeJsonByTable(dt, "module_id", "module_name","module_url", "module_fatherid", "0");
        context.Response.Write(json);
        context.Response.End();       
    }

    #region 根据DataTable生成EasyUI Tree Json树结构
    StringBuilder result = new StringBuilder();
    StringBuilder sb = new StringBuilder();   
    ///
    /// 根据DataTable生成EasyUI Tree Json树结构
    ///
    /// 数据源
    /// ID列
    /// Text列
    /// 节点Url
    /// 关系字段
    /// 父ID
    private string GetTreeJsonByTable(DataTable tabel, string idCol, string txtCol, string url, string rela, object pId)
    {
        result.Append(sb.ToString());
        sb.Clear();
        if (tabel.Rows.Count > 0)
        {
            sb.Append("[");
            string filer = string.Format("{0}='{1}'", rela, pId);
            DataRow[] rows = tabel.Select(filer);
            if (rows.Length > 0)
            {
                foreach (DataRow row in rows)
                {
                    sb.Append("{"id":"" + row[idCol] + "","text":"" + row[txtCol] + "","attributes":"" + row[url] + "","state":"open"");
                    if (tabel.Select(string.Format("{0}='{1}'", rela, row[idCol])).Length > 0)
                    {
                        sb.Append(","children":");
                        GetTreeJsonByTable(tabel, idCol, txtCol,url, rela, row[idCol]);
                        result.Append(sb.ToString());
                        sb.Clear();
                    }
                    result.Append(sb.ToString());
                    sb.Clear();
                    sb.Append("},");
                }
                sb = sb.Remove(sb.Length - 1, 1);
            }
            sb.Append("]");
            result.Append(sb.ToString());
            sb.Clear();
        }
        return result.ToString();
    }
    #endregion


    #region 创建数据
    protected static DataTable createDT()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("module_id");
        dt.Columns.Add("module_name");
        dt.Columns.Add("module_fatherid");
        dt.Columns.Add("module_url");
        dt.Columns.Add("module_order");

        dt.Rows.Add("C1", "全国", "0", "1.aspx", "1");
        dt.Rows.Add("M01", "广东", "C1", "2.aspx", "1");

        dt.Rows.Add("M0101", "深圳", "M01", "3.aspx", "100");
        dt.Rows.Add("M010101", "南山区", "M0101", "4.aspx", "1000");
        dt.Rows.Add("M010102", "罗湖区", "M0101", "", "1001");
        dt.Rows.Add("M010103", "福田区", "M0101", "", "1002");
        dt.Rows.Add("M010104", "宝安区", "M0101", "", "1003");
        dt.Rows.Add("M010105", "龙岗区", "M0101", "", "1004");

        dt.Rows.Add("M01010301", "上梅林", "M010103", "", "1002001");
        dt.Rows.Add("M01010302", "下梅林", "M010103", "", "1002002");
        dt.Rows.Add("M01010303", "车公庙", "M010103", "", "1002003");
        dt.Rows.Add("M01010304", "竹子林", "M010103", "", "1002004");
        dt.Rows.Add("M01010305", "八卦岭", "M010103", "", "1002005");
        dt.Rows.Add("M01010306", "华强北", "M010103", "", "1002006");

        dt.Rows.Add("M0102", "广州", "M01", "", "101");
        dt.Rows.Add("M010201", "越秀区", "M0102", "", "1105");
        dt.Rows.Add("M010202", "海珠区", "M0102", "", "1106");
        dt.Rows.Add("M010203", "天河区", "M0102", "", "1107");
        dt.Rows.Add("M010204", "白云区", "M0102", "", "1108");
        dt.Rows.Add("M010205", "黄埔区", "M0102", "", "1109");
        dt.Rows.Add("M010206", "荔湾区", "M0102", "", "1110");
        dt.Rows.Add("M010207", "罗岗区", "M0102", "", "1111");
        dt.Rows.Add("M010208", "南沙区", "M0102", "", "1112");
        return dt;
    }
    #endregion


    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}


代码如下:

    #region 根据DataTable生成EasyUI Tree Json树结构 
    StringBuilder result = new StringBuilder(); 
    StringBuilder sb = new StringBuilder();     
    ///  
    /// 根据DataTable生成EasyUI Tree Json树结构 
    ///  
    /// 数据源 
    /// ID列 
    /// Text列 
    /// 节点Url 
    /// 关系字段 
    /// 父ID 
    private string GetTreeJsonByTable(DataTable tabel, string idCol, string txtCol, string url, string rela, object pId) 
    { 
        result.Append(sb.ToString()); 
        sb.Clear(); 
        if (tabel.Rows.Count > 0) 
        { 
            sb.Append("["); 
            string filer = string.Format("{0}='{1}'", rela, pId); 
            DataRow[] rows = tabel.Select(filer); 
            if (rows.Length > 0) 
            { 
                foreach (DataRow row in rows) 
                { 
                    sb.Append("{"id":"" + row[idCol] + "","text":"" + row[txtCol] + "","attributes":"" + row[url] + """); 
                    if (tabel.Select(string.Format("{0}='{1}'", rela, row[idCol])).Length > 0) 
                    { 
                        //点击展开
                        sb.Append(","state":"closed","children":"); 
                        GetTreeJsonByTable(tabel, idCol, txtCol,url, rela, row[idCol]); 
                        result.Append(sb.ToString()); 
                        sb.Clear(); 
                    } 
                    result.Append(sb.ToString()); 
                    sb.Clear(); 
                    sb.Append("},"); 
                } 
                sb = sb.Remove(sb.Length - 1, 1); 
            } 
            sb.Append("]"); 
            result.Append(sb.ToString()); 
            sb.Clear(); 
        } 
        return result.ToString(); 
    } 
    #endregion  


    
 
 
 
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。












  • 相关文章推荐
  • jquery easyui利用DataGrid实现CRUD操作
  • Jqurey实现类似EasyUI的页面布局可改变左右的宽度
  • jquery easyui easyui-datetimebox 取消用户输入
  • jquery easyui通过class方式设置dialog
  • jquery easyUI创建分组属性编辑器
  • Jquery easyui之控件参数传递方法
  • Jquery easyui入门教程(1)
  • jquery easyui中combobox设为只读
  • jQuery的UI组件 EasyUI
  • Jquery easyui分页栏显示1到0怎么解决?
  • jquery easyui开发几点总结
  • jquery easyUI使用JS显示Dialog
  • jquery EasyUI导入js顺序详解
  • easyui的tabs update正确用法分享
  • jquery easyui表单重置扩展思路
  • jquery easyui自定义下拉框列表
  • Jquery EasyUI中弹出确认对话框
  • JQuery EasyUI使用笔记分享
  • Jquery easyui中Form表单提交注意事项
  • jquery easyui layout注意事项
  • jQuery easyui中DataGrid插件示例
  • Jquery easyUI 更新行示例


  • 站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,,E-mail:www_#163.com(请将#改为@)

    浙ICP备11055608号-3