0

需要在 ASP.NET MVC 4.0 中使用 Web Service API 开发 sql 报表服务的 Tree 导航。试过这个, http: //odetocode.com/articles/95.aspx并成功测试了 asp.net web 应用程序中的代码。现在我正在尝试使用 Web 服务“ReportService2010”和 jquery 树视图来执行相同的 mvc。这是示例代码控制器端`

    public static string ReportPath
    {
        get { return "/SSRSTest1"; }
    }
    public static char[] PathSeparatorArray
    {
        get { return pathSeparatorArray; }
    }

    public static string PathSeparatorString
    {
        get { return pathSeparatorString; }
    }

    protected static char pathSeparator = '/';
    protected static char[] pathSeparatorArray = { pathSeparator };
    protected static string pathSeparatorString = new string(pathSeparator, 1);`

    public ActionResult SSRSReportStructureInfo(string root)
    {
        ReportingService2010 rService = new ReportingService2010();
        rService.Credentials = System.Net.CredentialCache.DefaultCredentials;
        CatalogItem[] catalogItems;
        catalogItems = rService.ListChildren(ReportPath, true);
        List<TreeViewNode> nodes = new List<TreeViewNode>();
        nodes = BuildTree(catalogItems);
        return Json(nodes);
    }
     private List<TreeViewNode> BuildTree(CatalogItem[] catalogItems)
    {
        nodesList = new List<TreeViewNode>();
        foreach (CatalogItem item in catalogItems)
        {
            List<TreeViewNode> nodes = new List<TreeViewNode>();
            if (item.TypeName == "Report")
            {
                string path = item.Path.Remove(0, ReportPath.Length);
                string[] tokens = path.Split(PathSeparatorArray);
                BuildNodesFromTokens(tokens, 0, nodes);
                foreach (var child in nodes)
                {
                    nodesList.Add(new TreeViewNode()
                    {
                        text = child.text
                    });
                }
            }
        }
        return nodesList;
    }
     private void BuildNodesFromTokens(string[] tokens, int index, List<TreeViewNode> nodes)
    {
        TreeViewNode node = null;
        for (int i = 0; i < nodes.Count; i++)
        {
            if (nodes[i].text == tokens[index])
            {
                node = nodes[i];

                break;
            }
        }
        if (node == null)
        {
            node = new TreeViewNode();
            node.text = tokens[index];
            nodes.Add(node);

        }

        index++;
        if (tokens.Length > index)
        {
            BuildNodesFromTokens(tokens, index, nodes);
        }
    }

在索引视图中:

 <script src="../../Scripts/jquery-treeview-1.4.0.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-treeview-async-0.1.0.js" type="text/javascript"></script>

<ul id="fileSystemInfos" class="filetree"></ul><br />
<div id="fileSystemInfosControl"><a href="?#">Collapse All</a> | <a href="?#">Expand All</a></div>
  <script type="text/javascript">
 $(document).ready(function () {
     $('#fileSystemInfos').treeview({
         url: '/Home/SSRSReportStructureInfo',
         ajax: {
             type: 'post'
         },
         control: '#fileSystemInfosControl'
     })
 });
</script>

无法在 jquery 树视图的父级中添加子级。建议??

4

0 回答 0