getAllWebs: function (siteUrl, success, error) {
var ctx = new SP.ClientContext(siteUrl);
var web = ctx.get_site().get_rootWeb();
var result = [];
var level = 0;
var getAllWebsInner = function (web, result, success, error, isChild, siteUrl) {
level++;
var ctx = web.get_context();
var webs = web.get_webs();
ctx.load(webs, 'Include(Title,Url,Webs)');
ctx.executeQueryAsync(
function () {
for (var i = 0; i < webs.get_count(); i++) {
var web = webs.getItemAtIndex(i);
if (isChild)
siteHierarchy.subSiteInfo.push({ Title: web.get_title(), SiteUrl: web.get_url(), ParentUrl: siteUrl });
else
siteHierarchy.siteInfo.push({ Title: web.get_title(), SiteUrl: web.get_url(), Subsite: [] });
result.push(web);
if (web.get_webs().get_count() > 0) {
getAllWebsInner(web, result, success, error, true, web.get_url());
}
}
level--;
if (level == 0 && success) {
success(result);
}
},
error);
};
getAllWebsInner(web, result, success, error, false, siteUrl);
}
https://sharepoint.stackexchange.com/questions/130403/most-effective-way-to-get-all-sub-sites-under-a-site-collection-sub-の「Vadim Gremyachev」からの回答に基づくサイト使用 j。