2016-04-28 7 views
0

Mit dem kostenlosen Office365-Konto wurde die Sharepoint-Online-Standardwebsite erstellt. Darauf habe ich eine Liste namens "Product" erstellt. Wenn ich versuche, alle Websites-Listen zu erhalten, wird die Produktliste nicht aufgeführt. Nur 2 Listen (1) Komponiert Aussehen & (2) Masterpage Galerie werden aufgelistet. Unten ist der Code meiner App.js.Napa SharePoint-App findet die erstellte Sharepoint-Liste nicht

'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()); 
} 


})(); 

Antwort

0

Bitte zunächst einige Konzepte über Sharepoint-App realisieren:

App Web - Site, auf dem die App eingesetzt wird

Sie würden die App benötigen für den Zugriff auf und die Sharepoint-Komponenten, zu verwenden wie Listen, Inhaltstypen, Workflows und Seiten. In diesem Fall sollten alle Ihre SharePoint-Komponenten in einer separaten SharePoint-Website bereitgestellt werden, die als App Web bezeichnet wird.

Host-Web - Site, auf das die App

Der eigentliche Ort, an dem die Anwendung bereitgestellt wird, wird das Host-Web genannt installiert ist.

Aus Ihrem Code gelangen Sie über die Methode clientcontext.get_current(), die den aktuellen Kontext zurückgibt, in dem der Benutzer ausgeführt wird, zum App Web. Sie sehen nur zwei Listen in Ihrer Listbox. Wenn Sie darauf zugreifen möchten Informationen im Host-Web, ist ein anderer Ansatz erforderlich. Sie könnten ein Objekt namens AppSiteContext verwenden, Code unten ist für Ihre Referenz:

'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()); 
}