Coolite TreePanel 操作之一:TreePanel 刷新

脚本: 

function refreshTree(tree) {
            tree.el.mask('Loading...', 'x-loading-mask');
            Coolite.AjaxMethods.RefreshMenu({
                success: function(result) {
                    var nodes = eval(result);
                    tree.root.ui.remove();
                    tree.initChildren(nodes);
                    tree.root.render();
                    tree.el.unmask();
                },
                failure: function(msg) {

                    tree.el.unmask();

                    Ext.Msg.alert('Failure', '未能加载数据');

                }

            });
        }

 

Coolite.AjaxMethods.RefreshMenu方法:

 /// <summary>
        /// 刷新树 Json 获取
        /// </summary>
        /// <returns></returns>
        [AjaxMethod]
        public string RefreshMenu()
        {
            Coolite.Ext.Web.TreeNodeCollection nodes = LoadTree(this.TreePanelOrganization.Root);
            return nodes.ToJson();
        }

 

 

   /// <summary>
        /// 组织机构、组织角色树的加载 //WCF entity framework 方法
        /// </summary>
        /// <param name="nodes"></param>
        /// <returns>TreeNodeCollection</returns>
        private Coolite.Ext.Web.TreeNodeCollection LoadTree(Coolite.Ext.Web.TreeNodeCollection nodes)
        {

          
            if (nodes == null)
            {
                nodes = new Coolite.Ext.Web.TreeNodeCollection();
            }//根节点为null时

            TreePanelOrganization.Root.Clear();

            Coolite.Ext.Web.TreeNode node = new Coolite.Ext.Web.TreeNode("Hisoft", "Hisoft", Icon.Group);
            node.Qtip = "Hisoft";
            nodes.Add(node);
            node.Expanded = true;

            // OrganizationService.OrganizationServiceClient client = new PMS.Web.Admin.OrganizationService.OrganizationServiceClient();
            //  client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;

            //所有父节点的加载
            DCC_ResorganizationList organizationlist = client.GetOrganizationList("");

            foreach (var superCode in organizationlist.ToList())
            {
                Coolite.Ext.Web.TreeNode supernode = new Coolite.Ext.Web.TreeNode();
                string parentcode = superCode.OrganizationCode;
                supernode.NodeID = superCode.OrganizationCode;
                supernode.Text = superCode.OrganizationName;
                supernode.Qtip = superCode.OrganizationFullName;
                supernode.Cls = superCode.OrganizationID;
                //supernode.Expanded = true;
                supernode.Icon = Icon.GroupKey;
                //supernode.CustomAttributes.Add(new ConfigItem(
                node.Nodes.Add(supernode);
                LoadOrgRoleByOrganizationID(superCode.OrganizationID, supernode);
                CreateCycleTree(parentcode, supernode);
            }

            return nodes;

            //linq to sql class 方法
            //IList<RES_Organization> OrgSuperDepartment = OrgData.GetCycleOrganization("", context);
            //foreach (var superCode in OrgSuperDepartment)
            //{
            //    Coolite.Ext.Web.TreeNode supernode = new Coolite.Ext.Web.TreeNode();
            //    supernode.NodeID = superCode.organization_code;
            //    supernode.Text = superCode.organization_name;
            //    supernode.Qtip = superCode.organization_full_name;
            //    supernode.Icon = Icon.GroupKey;
            //    node.Nodes.Add(supernode);
            //    CreateCycleTree(supernode.NodeID, supernode);

            //}
          
        }


        /// <summary>
        /// 递归加载树
        /// </summary>
        /// <param name="code">父节点的code</param>
        /// <param name="parentcode">父节点</param>
        private void CreateCycleTree(string code, Coolite.Ext.Web.TreeNode parentcode)
        {
            // OrganizationService.OrganizationServiceClient client = new PMS.Web.Admin.OrganizationService.OrganizationServiceClient();

            //根据父节点的ID得到该节点下的所有子节点
            DCC_ResorganizationList orgDepartment = client.GetOrganizationList(code);

            // IList<RES_Organization> orgDepartment = OrgData.GetCycleOrganization(code, context);

            foreach (var org in orgDepartment.ToList())
            {
                Coolite.Ext.Web.TreeNode node = new Coolite.Ext.Web.TreeNode();
                string orgparentcode = org.OrganizationCode;
                node.NodeID = org.OrganizationCode;
                node.Text = org.OrganizationName;
                node.Qtip = org.OrganizationFullName;
                node.Cls = org.OrganizationID;
                node.Icon = Icon.GroupGo;
                parentcode.Nodes.Add(node);
                LoadOrgRoleByOrganizationID(org.OrganizationID, node);
                CreateCycleTree(orgparentcode, node);
            }

        }

 

 

脚本注册:

  string JsFunction = "refreshTree(#{TreePanelOrganization})";
                //string JsFunction = "alert('dd');";
                //string JsFunction = "refreshTree()";
                Coolite.Ext.Web.ScriptManager sm = Coolite.Ext.Web.ScriptManager.GetInstance(HttpContext.Current);
                sm.AddScript(string.Format("{0};", JsFunction));

 

 

你可能感兴趣的:(TreePanel)