2017-03-07 52 views
-1

獲取URL我使用下面的JavaScript代碼來獲得在SharePoint 2013的所有列表的頭銜,我怎麼能適應這個返回每個列表的網址呢?的SharePoint 2013 - 的JavaScript從列表

我已經厭倦了這一點,但它不工作:

//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

名單地址可以通過SPList.RootFolder property檢索,在你的榜樣行:

clientContext.load(collList); 

需要與

被替換
clientContext.load(collList,'Include(RootFolder.ServerRelativeUrl)'); 

它告訴構造一個查詢返回RootFolder.ServerRelativeUrlList對象的屬性。

這裏是我的版本,檢索列表,並打印其網址:

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()); 
    } 
); 
相關問題