Created
April 11, 2015 14:20
-
-
Save vgrem/b1e5273139607363bef9 to your computer and use it in GitHub Desktop.
Enumerate webs of site collection using SharePoint JSOM
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
function enumWebs(propertiesToRetrieve, success,error) | |
{ | |
var ctx = SP.ClientContext.get_current(); | |
var rootWeb = ctx.get_site().get_rootWeb(); | |
var result = []; | |
var level = 0; | |
ctx.load(rootWeb,propertiesToRetrieve); | |
result.push(rootWeb); | |
var colPropertiesToRetrieve = String.format('Include({0})',propertiesToRetrieve.join(',')); | |
var enumWebsInner = function(web,result,success,error) | |
{ | |
level++; | |
var ctx = web.get_context(); | |
var webs = web.get_webs(); | |
ctx.load(webs,colPropertiesToRetrieve); | |
ctx.executeQueryAsync( | |
function(){ | |
for(var i = 0; i < webs.get_count();i++){ | |
var web = webs.getItemAtIndex(i); | |
result.push(web); | |
enumWebsInner(web,result,success,error); | |
} | |
level--; | |
if (level == 0 && success) | |
success(result); | |
}, | |
error); | |
}; | |
enumWebsInner(rootWeb,result,success,error); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment