循环通过站点创建站点地图

时间:2013-10-17 19:55:00

标签: javascript jquery loops recursion iteration

我需要遍历一个站点,列出所有它的顶级站点,然后列出每个站点子站点,然后每个站点子站点等,直到我最终得到我的整个站点集合的树。我不知道如何循环我的功能来实现这一目标。

这是我最初的html:

      <div id="treeviewDiv" style="width:200px;height:150px;overflow:scroll">
        <ui id="treeviewList"></ui>
      </div>

这是我正在使用的Javascript:

所以我尝试这样做的方式是在找到我的第一个网站后,运行$()。SPServices给我一个基于$(this).attr(url)

function getSiteTree(){
    var tree = $('#treeviewList');
    var rootsite = window.location.protocol + "//" + window.location.hostname;

$().SPServices({
    operation: "GetWebCollection",
    webURL: rootsite,
    async: true,
    completefunc(xData, Status){
        $(xData.responseXML).find("Web").each(function(){
            tree.append("<li value='" + $(this).attr("Url") + "'>" + $(this).attr("Title") + "</li>");

             $().SPServices({
                operation: "GetWebCollection",
                webURL: $(this).attr("Url"),
                async: true,
                completefunc: function(xData, Status){
                    if($(xDate.responseXML.find("Web"))){
                        $(xData.responseXML).find("Web").each(function(){
                        strHTMLTopSites += "<li value='" + $(this).attr("Url") + "'>" + $(this).attr("Title") + "</li>";

*** I kind of gave up at this point, it seemed like I'd just be copying the amount of times I run this function arbitrarily which seemed like a bad way to do it.  
                      });
                    }

        });
    }
});

}

这是运行$()时获得的XML响应.SPServices:

<Webs xmlns="http://schemas.microsoft.com/sharepoint/soap/">
   <Web Title="Subsite1_Name" Url="http://Server_Name/[sites]/
      [Site_Name]/[Subsite1]" />
   <Web Title="Subsite2_Name" Url="http://Server_Name/[sites]/
      [Site_Name]/[Subsite2]" />
</Webs>

当没有子网站时,这是XML:

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetWebCollectionResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/"><GetWebCollectionResult>`<Webs />`</GetWebCollectionResult></GetWebCollectionResponse></soap:Body></soap:Envelope>

我正在努力创造这样的东西:

<div class="demo-section">
    <ul id="treeview">
        <li>Furniture
            <ul>
                <li>Tables & Chairs</li>
                <li>Sofas</li>
                <li>Occasional Furniture</li>
                <li>Childerns Furniture</li>
                <li>Beds</li>
            </ul>
        </li>
        <li>Decor
            <ul>
                <li>Bed Linen</li>
                <li>Throws</li>
                <li>Curtains & Blinds</li>
                <li>Rugs</li>
                <li>Carpets</li>
            </ul>
        </li>
        <li>Storage
            <ul>
                <li>Wall Shelving</li>
                <li>Kids Storage</li>
                <li>Baskets</li>
                <li>Multimedia Storage</li>
                <li>Floor Shelving</li>
                <li>Toilet Roll Holders</li>
                <li>Storage Jars</li>
                <li>Drawers</li>
                <li>Boxes</li>
            </ul>
        </li>
    </ul>
</div>

0 个答案:

没有答案