我使用以下JavaScript代码获取SharePoint 2013中所有列表的标题。我如何调整此值以返回每个列表的URL?
我已经厌倦了,但它不起作用:
//listUrl = oList.get_url();
//console.log(listUrl);
代码:
function retrieveAllListProperties() {
var clientContext = new SP.ClientContext('/StrategicProjectOffice');
var oWebsite = clientContext.get_web();
this.collList = oWebsite.get_lists();
clientContext.load(collList);
clientContext.executeQueryAsync(
Function.createDelegate(this, this.onQuerySucceeded)
);
}
function onQuerySucceeded() {
var listTitle = '';
var listEnumerator = collList.getEnumerator();
while (listEnumerator.moveNext()) {
var oList = listEnumerator.get_current();
listTitle = oList.get_title();
//listUrl = oList.get_url();
//console.log(listUrl);
if (listTitle.indexOf("SPO") >= 0) {
getItemsFromView(listTitle, "All Tasks");
}
}
}
答案 0 :(得分:0)
可以通过SPList.RootFolder
property检索列表网址,在您的示例中可以找到以下行:
clientContext.load(collList);
需要替换为
clientContext.load(collList,'Include(RootFolder.ServerRelativeUrl)');
告诉构造一个查询以返回RootFolder.ServerRelativeUrl
对象的List
属性。
实施例
这是我的版本,它检索列表并打印其网址:
var ctx = SP.ClientContext.get_current();
var web = ctx.get_web();
var lists = web.get_lists();
ctx.load(lists,'Include(RootFolder.ServerRelativeUrl)');
ctx.executeQueryAsync(
function () {
for(var i = 0; i < lists.get_count(); i++){
var list = lists.getItemAtIndex(i);
var listUrl = list.get_rootFolder().get_serverRelativeUrl();
console.log(listUrl);
}
},
function(sender,args){
console.log(args.get_message());
}
);