0

我有以下问题。在 SharePoint Online 环境中,安装了一个 SharePoint 托管应用程序,该应用程序将其数据存储在一个列表中。我需要从此列表中获取数据,但 SharePoint 托管应用程序的 Web 不允许在同一应用程序 Web/应用程序上下文之外进行任何类型的访问。

有没有已知的解决方案?我知道应用程序网络的保护是有原因的,但我想知道 Sharepoint 托管加载项是否真的无法在其上下文之外共享数据?

4

1 回答 1

1
// Get Context of App Web 
var context = new SP.ClientContext("<<SharePoint App Web Url>>");
//Set Proxy web to get data of parent web apps
var factory = new SP.ProxyWebRequestExecutorFactory("<<SharePoint App Web Url>>");
context.set_webRequestExecutorFactory(factory);
//get parent web context
var appContextSite = new SP.AppContextSite(context, "<<SharePoint App Host Web Url>>");
web = appContextSite.get_web();

//get parent web list 
var lists = appContextSite.get_web().get_lists().getByTitle("<<List Name>>");
var caml = new SP.CamlQuery();
//Ceate CAML Query to get items from list
caml.set_viewXml('View><Query></Query></View>');
var listItems = lists.getItems(caml);
//load context of listItems
context.load(listItems);
context.executeQueryAsync(function () {
    var listInfo = '';
    var listEnumerator = listItems.getEnumerator();
    while (listEnumerator.moveNext()) {
        var oList = listEnumerator.get_current();
        listInfo += ' ID: ' + oList.get_id().toString() + '\n';
    }
    alert(listInfo);
    //here you can get list data 
},
function (sender, args) {
    console.log(args.errorMessage);
});
于 2017-01-31T12:43:14.090 回答