我在自定义导航中写出每个子网:
navigation = function (clientContext, web) {
this.webCollection = web.getSubwebsForCurrentUser(null);
clientContext.load(web);
clientContext.load(this.webCollection, 'Include(Title, Url)');
clientContext.executeQueryAsync(Function.createDelegate(navigationSuccess), Function.createDelegate(navigationFailed));
},
navigationSuccess = function () {
var webEnumerator = this.webCollection.getEnumerator();
while (webEnumerator.moveNext()) {
var web = webEnumerator.get_current();
// Writing out title/url for sub web.
}
},
在navigationSuccess中,我想检查这个子网是否包含任何子网。这可能吗?我在get_current()之后尝试了web.get_webs()但是我需要先加载(在一个类似于“navigation”的新函数中)?
如果当前的子网包含任何子网,感觉就像检查/计数的大过程一样吗?
答案 0 :(得分:2)
以下示例演示了如何使用SharePoint JSOM检索子站点的数量:
function getWebsCount(parentWeb,success,error)
{
var ctx = parentWeb.get_context();
var webs = parentWeb.get_webs(); //parentWeb.getSubwebsForCurrentUser(null);
ctx.load(webs);
ctx.executeQueryAsync(
function(){
success(webs.get_count());
},
error);
}
用法
var ctx = SP.ClientContext.get_current();
var web = ctx.get_web();
getWebsCount(web,function(count){
console.log(String.format('Sub sites count: {0}',count));
},
function(sender,args){
console.log(args.get_message());
});