2013-02-01 23 views
0

我在SharePoint託管應用程序中遇到問題。我想要做的就是獲取應用程序正在運行的網絡列表,並使用這些列表。SharePoint應用程序開發與HostWeb的AppWeb通信

有了這個代碼,我得到的AppWeb名單:

this.web = context.get_web(); 
this.lists = this.web.get_lists(); 
this.context.load(this.lists); 

我已經嘗試過類似的東西,以獲得從HostWeb名單:

this.context = new SP.ClientContext("https://sharepoint-server.com/_layouts/15/start.aspx#/"); 
var oWebsite = client.get_web(); 
this.lists = oWebsite.get_lists(); 
this.context.load(this.lists); 

但它不會返回來自這個網站的列表。

有人可以幫我嗎?

非常感謝!

回答

0

嘗試在調用Load方法後調用this.context.ExecuteQuery()。上下文中的對象在ExecuteQuery()調用之後纔可用。

HTH。

0

喊你需要調用一個回調函數「executeQueryAsync」的方法得到的結果的「負荷」功能後:請參閱本example code from MSDN

function retrieveAllListProperties(siteUrl) { 
    var clientContext = new SP.ClientContext(siteUrl); 
    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 listInfo = ''; 
    var listEnumerator = collList.getEnumerator(); 

    while (listEnumerator.moveNext()) { 
     var oList = listEnumerator.get_current(); 
     listInfo += 'Title: ' + oList.get_title() + ' Created: ' + oList.get_created().toString() + '\n'; 
} 
alert(listInfo); } 

function onQueryFailed(sender, args) { 
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); }