当前位置: 首页 > 工具软件 > MzTreeView > 使用案例 >

MzTreeView 2.0 后台生成示例

隗和裕
2023-12-01

   private void ModuleTreeView()
    {
        //获取职位列表

        IList<ModuleInfo> moduleList = moduleBLL.GetListModule();

        //为MzTreeView生成数据源
        StringBuilder js_ModuleTreeView = new StringBuilder();
        js_ModuleTreeView.Append(@"<script language='javascript' type='text/javascript'>");
        js_ModuleTreeView.Append(@"var data={};");//为MzTreeView生成数据源

        if ((moduleList != null) && (moduleList.Count > 0))
        {
            js_ModuleTreeView.Append("data['-1_0001']='text:模块功能;';");
            foreach (ModuleInfo moduleInfo in moduleList)
            {
                if (moduleInfo.ParentID == 0)
                {
                    js_ModuleTreeView.Append("data['0001_" + moduleInfo.ModuleID.ToString() + "']='text:" + moduleInfo.Name + ";data:" + "ModuleID=" + moduleInfo.ModuleID.ToString() + ";");
                    //js_ModuleTreeView.Append(@"target:ModuleData;");
                    //js_ModuleTreeView.Append(@"target:ModuleList.aspx;");
                    //js_ModuleTreeView.Append("method:window.parent.document.main(iframe_ModuleData).location.reload();");
                    js_ModuleTreeView.Append(@" ';");

                    IList<FunctionInfo> functionList = functionBLL.GetFunctionsByModuleID(moduleInfo.ModuleID);
                    if (functionList == null || functionList.Count <= 0) continue;
                    //为MzTreeView添加模块功能数据源
                    foreach (FunctionInfo function in functionList)
                    {
                        js_ModuleTreeView.Append("data['" + moduleInfo.ModuleID.ToString() + "_" + moduleInfo.ModuleID.ToString() + function.FunctionID.ToString() + "']='text:" + function.CNName + ";data:FunctionID=" + function.FunctionID.ToString() + ";");
                        //js_ModuleTreeView.Append(@"target:ModuleData;");
                        js_ModuleTreeView.Append(@" ';");
                    }
                }
                else
                {
                    js_ModuleTreeView.Append("data['" + moduleInfo.ParentID.ToString() + "_" + moduleInfo.ModuleID.ToString() + "']='text:" + moduleInfo.Name + ";data:" + "ModuleID=" + moduleInfo.ModuleID.ToString() + ";");//绑定Data数据,可用node.get('data')获得ModuleID='1'这样的字符串
                    //js_ModuleTreeView.Append(@"target:ModuleData;");
                    js_ModuleTreeView.Append(@" ';");

                    IList<FunctionInfo> functionList = functionBLL.GetFunctionsByModuleID(moduleInfo.ModuleID);
                    if (functionList == null || functionList.Count <= 0) continue;
                    //为MzTreeView添加模块功能数据源
                    foreach (FunctionInfo function in functionList)
                    {
                        js_ModuleTreeView.Append("data['" + moduleInfo.ModuleID.ToString() + "_" + moduleInfo.ModuleID.ToString() + function.FunctionID.ToString() + "']='text:" + function.CNName + ";data:FunctionID=" + function.FunctionID.ToString() + ";");
                        //js_ModuleTreeView.Append(@"target:ModuleData;");
                        js_ModuleTreeView.Append(@" ';");
                    }
                }
            }

        }
        js_ModuleTreeView.Append(@" var tree=new  MzTreeView();");
        js_ModuleTreeView.Append(@"tree.dataSource=data;");
        js_ModuleTreeView.Append(@"tree.useCheckbox=true;");
        js_ModuleTreeView.Append(@"document.write(tree.render());");
        js_ModuleTreeView.Append(@"tree.expandAll('0001');");
        js_ModuleTreeView.Append(@"</script>");

        //getElementById('iframe_PosTreeView')getElementById('oDiv_PosTreeView')
        //Page.Header.Controls.Add(new LiteralControl(js_ModuleTreeView.ToString()));
        Page.FindControl("TreeView").Controls.Add(new LiteralControl(js_ModuleTreeView.ToString()));

        //将树生成到指定位置

        //如果要添加到head中,可用代码如:

       //Page.Header.Controls.Addd(new LiteralControl(js_ModuleTreeView.ToString()))

    }

 类似资料: