0

我需要遍历一个站点以列出它的所有顶级站点,然后是每个站点的子站点,然后是每个子站点的子站点,等等,直到我最终得到整个站点集的树。我不知道如何循环我的函数来完成这个。

这是我最初的 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.  
                      });
                    }

        });
    }
});

}

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

<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>
4

0 回答 0