2016-04-28 3 views
0

無料のoffice365アカウントを使用して、デフォルトのsharepointオンラインWebサイトが作成されました。その上に私は「製品」というリストを作成しました。すべてのウェブサイトリストを取得しようとすると、商品リストは表示されません。唯一の2つのリスト(1)構図&(2)マスターページギャラリーが表示されています。以下は私のApp.jsコードです。Napa SharePointアプリケーションが作成した共有ポイントリストを見つけられない

'use strict'; 

var context = SP.ClientContext.get_current(); 
var user = context.get_web().get_currentUser(); 
var web = context.get_web(); 
var lists = context.get_web().get_lists(); 
var listItems; 

(function() { 

// This code runs when the DOM is ready and creates a context object which is 
// needed to use the SharePoint object model 
$(document).ready(function() { 
    getAllLists(); 
}); 

// This function prepares, loads, and then executes a SharePoint query to get 
// the current users information 
function getAllLists() { 
    context.load(lists); 
    context.executeQueryAsync(onGetListsSuccess, onGetListsFail); 

} 

// This function is executed if the above call is successful 
// It replaces the contents of the 'message' element with the user name 
function onGetListsSuccess() { 
    $('#message').text('Hello ' + lists.get_count().toString()); 
    //$('#message').text('Hello ' + web.get_title().toString()); 

var listEnumerator = lists.getEnumerator(); 
var selectListBox = document.getElementById("ListItemListBox"); 


if (selectListBox.hasChildNodes()) { 
    while (selectListBox.childNodes.length >= 1) { 
     selectListBox.removeChild(selectListBox.firstChild); 
    } 
} 
// Traverse the elements of the collection, and load the name of 
// each list into the dropdown list box. 
while (listEnumerator.moveNext()) { 
    var selectOption = document.createElement("option"); 
    selectOption.value = listEnumerator.get_current().get_title(); 
    selectOption.innerText = listEnumerator.get_current().get_title(); 
    selectListBox.appendChild(selectOption); 
} 

} 

// This function is executed if the above call fails 
function onGetListsFail(sender, args) { 
    alert('Failed to get user name. Error:' + args.get_message()); 
} 


})(); 

答えて

0

まずSharePointのアプリについてのいくつかの概念を実現してください:

アプリケーションのWeb - サイトアプリケーションがデプロイされているが

アクセスし、SharePointコンポーネントなどを使用するには、アプリケーションが必要となりますリスト、コンテンツタイプ、ワークフロー、およびページとして使用できます。この場合、すべてのSharePointコンポーネントを、App Webと呼ばれる別のSharePointサイトに展開する必要があります。

ホストのWeb - アプリケーションは

アプリは、ホストのWebと呼ばれている展開されている実際のサイトに設置されているサイト。

コードからは、ユーザーが現在実行しているコンテキストを返すclientcontext.get_current()メソッドを使用してApp Webにアクセスします。リストボックスに2つのリストしか表示されません。アクセスする場合はホストWebの情報には、別の方法が必要です。 AppSiteContextというオブジェクトを使用すると、以下のコードが参照用に使用されます。

'use strict'; 
var web; 
var hostcontext; 
var lists; 
$(document).ready(function() { 
    var hostUrl = decodeURIComponent(getQueryStringParameter("SPHostUrl")); 
    var currentcontext = new SP.ClientContext.get_current(); 
    hostcontext = new SP.AppContextSite(currentcontext, hostUrl); 
    web = hostcontext.get_web(); 
    lists = web.get_lists(); 
    getAllLists(); 
}); 

function getAllLists() { 
    context.load(lists); 
    context.executeQueryAsync(onGetListsSuccess, onGetListsFail); 
} 

// This function is executed if the above call is successful 
// It replaces the contents of the 'message' element with the user name 
function onGetListsSuccess() { 
    $('#message').text('Hello ' + lists.get_count().toString()); 
    var listEnumerator = lists.getEnumerator(); 
    // Traverse the elements of the collection, and load the name of 
    // each list into the dropdown list box. 
    while (listEnumerator.moveNext()) { 
     alert(listEnumerator.get_current().get_title()); 
    } 
} 

//this is just the sample function that's in all the MS samples 

function getQueryStringParameter(paramToRetrieve) { 
    var params = 
    document.URL.split("?")[1].split("&"); 
    var strParams = ""; 
    for (var i = 0; i < params.length; i = i + 1) { 
     var singleParam = params[i].split("="); 
     if (singleParam[0] == paramToRetrieve) 
      return singleParam[1]; 
    } 
} 

// This function is executed if the above call fails 
function onGetListsFail(sender, args) { 
    alert('Failed to get user name. Error:' + args.get_message()); 
} 
関連する問題