Created
July 5, 2016 14:33
-
-
Save PaulSpoerry/bd2f2a99c475cc3a0c06689c953fdc1a to your computer and use it in GitHub Desktop.
List all subsites within a SharePoint container by iterating over SPServices.SPGetCurrentSite()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery.noConflict(); | |
(function( $ ) { | |
//inject SPServices | |
var sps = document.createElement('script'); | |
sps.src = "https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices-2014.02.min.js"; | |
document.getElementsByTagName('head')[0].appendChild(sps); | |
// Code in here | |
var tree = $('#treeviewList'); | |
var rootsite = $().SPServices.SPGetCurrentSite(); | |
var siteEnd = false; | |
getSubSite(rootsite); | |
function getSubSite(url){ | |
$().SPServices({ | |
operation: "GetWebCollection", | |
webURL: url, | |
async: true, | |
completefunc: function(xData, Status) { | |
var siteUrl; | |
var siteCount = $(xData.responseXML).find("Web").length; | |
if(siteCount == 0){ | |
console.log("end of branch"); | |
siteEnd = true; | |
}else{ | |
$(xData.responseXML).find("Web").each(function() { | |
siteUrl = $(this).attr("Url"); | |
console.log(siteUrl); | |
getSubSite(siteUrl); | |
}); | |
} | |
} | |
}); | |
} | |
// End code in here | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment