L'app Hosted SharePoint non ottiene le mie liste
-
10-12-2019 - |
Domanda
Sto sviluppando un'app di SharePoint-Hosted per SharePoint 2013 (in Office365), ma ho problemi ad accedere alle liste all'interno di un'app di SharePoint-Hosted.
Il mio codice sta stampando bene gli elenchi, ma mi mostra solo la lista "Looks Looks 'e l'elenco' Master Page Gallery ', non riesco ad accedere agli elenchi che ho creato nel mio sito di SharePoint. .
E quando provo ad accedere all'elenco "Contatti" (che esiste nel sito di SharePoint in cui distributo l'app), ha questa eccezione:
Elenco 'Contatti' non esiste sul sito con URL ' https://mysharepointite-03ea186502297f.sharepoint.com/sphostedapp12
Sembra così che la mia app sia in esecuzione da un altro sito rispetto al mio sito principale, ed è per questo che non riesco ad accedere all'elenco esistenti dal mio sito principale ...
Qualcuno sa come risolvere questo e accedere agli elenchi esistenti nel sito principale?
Grazie mille!
Ecco il mio codice App.JS:
'use strict';
var gobbe = window.gobbe || {};
gobbe.Contacts;
gobbe.ContactList = function () {
// private members
var createItem = function (lname, fname, bphone) {
var ctx = new SP.ClientContext.get_current();
var list = ctx.get_web().get_lists().getByTitle('Contacts');
ctx.load(list);
var listItemCreationInfo = new SP.ListItemCreationInformation();
var newContact = list.addItem(listItemCreationInfo);
newContact.set_item('Last Name', lname);
newContact.set_item('First Name', fname);
newContact.set_item('Business Phone', bphone);
newContact.update();
ctx.executeQueryAsync(success, error);
},
readAll = function () {
// Not implemented
},
readAllSuccess = function () {
// Not implemented
},
updateItem = function () {
// Not implemented
},
updateItem = function (id, lname, fname, bphone) {
// Not implemented
},
removeItem = function (id) {
// Not implemented
},
success = function () {
readAll();
},
error = function (sender, args) {
alert(args.get_message());
}
// public interface
return {
createContact: createItem,
updateContact: updateItem,
deleteContact: removeItem
}
}();
gobbe.Collections = function () {
// private members
var site,
listCollection,
getListCollection = function () {
var ctx = new SP.ClientContext.get_current();
site = ctx.get_web();
ctx.load(site);
listCollection = site.get_lists();
ctx.load(listCollection, 'Include(Title,Id,Fields.Include(Title,Description))');
ctx.executeQueryAsync(success, failure);
},
success = function () {
var html = [];
// List Information
html.push('<ul>');
var listEnumerator = listCollection.getEnumerator();
while (listEnumerator.moveNext()) {
// List Title
html.push('<li>');
html.push(listEnumerator.get_current().get_title());
html.push('<ul>');
// Fields Names
var fieldEnumerator = listEnumerator.get_current().get_fields().getEnumerator();
while (fieldEnumerator.moveNext()) {
html.push('<li>');
html.push(fieldEnumerator.get_current().get_title());
html.push('</li>');
}
html.push('</ul></li>')
}
html.push('</ul>');
// Show results
$('#displayDiv').html(html.join(''));
},
failure = function (sender, args) {
alert(args.get_message());
}
// public interface
return {
execute: getListCollection
}
}();
$().ready(function () {
// Show lists
gobbe.Collections.execute();
// Try to add a contact
gobbe.ContactList.createContact('Cox', 'Brian', '555-555-5555');
alert('Contact Created!');
// Update it
gobbe.ContactList.updateContact(1, 'Cox', 'Brian', '111-111-1111');
alert('Contact Updated!');
// Delete it
gobbe.ContactList.deleteContact(1);
alert('Contact Deleted!');
});
. Soluzione
Le app funzionano in un dominio diverso rispetto al tuo web host. Quindi, è una chiamata di un dominio croce quando si tenta di accedere ad alcuni elenchi che risiede nel tuo web host dalla tua applicazione web. I browser normalmente non consentono di effettuare questi chiamati cross dominio per motivi di sicurezza. Tuttavia, in app, per interagire con il web host, c'è una biblioteca chiamata sp.requestexecutor.js, che è un elaboratore del dominio croce che è possibile utilizzare per effettuare queste chiamate. Si prega di dare un'occhiata ai seguenti link che ti aiuteranno a rendere queste chiamate cross dominio per accedere ai dati Web host all'interno di un'app Web.
http://msdn.microsoft.com/en-in/library/ fp179927.aspx
http://www.mavention.com/ Blog / SharePoint-App-Reading-Data-Data-Da-host-Web
http://blogs.mssdn.com/b/officeapps/archive/2012/11/11/29/solving-dRoss-domain-problems-in-apps-for-sharepoint.aspx Spero che ti aiuti.
Altri suggerimenti
Sembra che tu abbia dimenticato di dare le tue autorizzazioni dell'app: la lista dei "contatti" non esiste sul sito con URL.
Quando si installa un'app ti verrà richiesta i diritti di accedere a una libreria o un elenco specifico per esempio.
Dovrai aggiungere qualcosa come questo ... Esempio di cosa appare il markup in un'app manifest:
<AppPermissionRequests>
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web/list" Right="Write"/></AppPermissionRequests>
Per accedere all'elenco dal Web host è necessario fare affidamento sui "token standard" e quindi utilizzare Eithe JSOM o Poggia API per accedere ai dati.
//Get the URI decoded URLs.
hostweburl =
decodeURIComponent(
getQueryStringParameter("SPHostUrl")
);
appweburl =
decodeURIComponent(
getQueryStringParameter("SPAppWebUrl")
);
.
Allora potresti usare qualcosa del genere:
// Initialize the RequestExecutor with the app web URL.
executor = new SP.RequestExecutor(appweburl);
// Issue the call against the host web.
// To get the title using REST we can hit the endpoint:
// app_web_url/_api/SP.AppContextSite(@target)/web/title?@target='siteUrl'
// The response formats the data in the JSON format.
// The functions successHandler and errorHandler attend the
// success and error events respectively.
executor.executeAsync(
{
url:
appweburl +
"/_api/SP.AppContextSite(@target)/web/title?@target='" +
hostweburl + "'",
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: successHandler,
error: errorHandler
}
);
.