我发现以下帖子会返回网站中所有网站上所有列表中的项目。我试图弄清楚如何返回列表项计数而不是列表项。任何援助将不胜感激。
JSOM dynamicly get two announcements from all lists in all webs
更新:
我可以使用以下命令返回网站上所有文档库的详细信息:
function retrieveAllListProperties() {
var clientContext = new SP.ClientContext.get_current();
var oWebsite = clientContext.get_web();
this.collList = oWebsite.get_lists();
clientContext.load(collList);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded() {
var tCount = 0;
var listInfo = 'Lists on the current site:' + '\n\n';
var listEnumerator = collList.getEnumerator();
while (listEnumerator.moveNext()) {
var oList = listEnumerator.get_current();
if (oList.get_baseTemplate() === 101) {
listInfo += 'URL: ' + oList.get_parentWebUrl() + ' | Title: ' + oList.get_title() + ' | BaseType: ' + oList.get_baseTemplate() + ' | Count: ' + oList.get_itemCount() + '\n';
tCount += + oList.get_itemCount();
}
}
listInfo += '\nTotal Documents: ' + tCount;
console.log(listInfo);
}
function onQueryFailed(sender, args) {
console.log('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
我可以使用以下方法返回网站集的所有网站和子网站:
function getAllWebs(success,error)
{
var siteUrl = '/sites/usaraf/g357';
var ctx = SP.ClientContext.get_current();
var web = ctx.get_site().get_rootWeb();
var result = [];
var level = 0;
var getAllWebsInner = function(web,result,success,error)
{
level++;
var ctx = web.get_context();
var webs = web.get_webs();
ctx.load(webs,'Include(Title,ServerRelativeUrl,Webs)');
ctx.executeQueryAsync(
function(){
for(var i = 0; i < webs.get_count();i++){
var web = webs.getItemAtIndex(i);
result.push(web);
if(web.get_webs().get_count() > 0) {
getAllWebsInner(web,result,success,error);
}
}
level--;
if (level == 0 && success)
success(result);
},
error);
};
getAllWebsInner(web,result,success,error);
}
getAllWebs(
function(allwebs){
for(var i = 0; i < allwebs.length;i++){
console.log(allwebs[i].get_title() + "-" + allwebs[i].get_serverRelativeUrl());
}
},
function(sender,args){
console.log(args.get_message());
});
我正在试图弄清楚如何将两者结合在一起,所以我为所有网站和子网站上的所有指定列表返回以下内容。
Lists on the current site:
URL: /sites/usaraf-ea/visa | Title: Applications | BaseType: 101 | Count: 24
URL: /sites/usaraf-ea/visa | Title: docDropOff | BaseType: 101 | Count: 28
URL: /sites/usaraf-ea/visa | Title: docResources | BaseType: 101 | Count: 5
URL: /sites/usaraf-ea/visa | Title: Documents | BaseType: 101 | Count: 2
URL: /sites/usaraf-ea/visa | Title: Site Assets | BaseType: 101 | Count: 23
Total Documents: 82
答案 0 :(得分:0)
获得listitem collection后,您可以致电internal async Task OnAppearing()
{
await NavigateModalLogin();
}
ICommand _loginNav;
public ICommand NavigatePopup
{
get
{
if (_loginNav == null)
{
_loginNav = new Command(async () => await NavigateModalLogin());
}
return _loginNav;
}
}
async Task NavigateModalLogin()
{
await _navService.PushModalAsync<NormalModalViewModel>();
}
返回项目计数。
示例代码:
listItems.get_count()