【问题标题】:Query SharePoint 2013 List from Another Site Collection从另一个网站集中查询 SharePoint 2013 列表
【发布时间】:2016-03-10 06:53:25
【问题描述】:

我已经成功地使用 SPServices 来查询我的网站集上的 SharePoint 列表。现在,我为另一个团队准备了第二个网站集,该团队希望查看已托管在我的第一个网站集上的数据(不,我们不能使用相同的网站集)。我想通过查询原始网站集中的数据来创建 CEWP 视图,但是当我从第二个网站集中运行它时,该代码不起作用。以下是在第一个网站上有效的方法:

$().SPServices({
    operation: 'GetListItems',
    async: false,
    listName: 'Requests',
    CAMLViewFields: "<ViewFields>" +
                        "<FieldRef Name='ID' />" +
                        "<FieldRef Name='Title' />" +
                        "<FieldRef Name='Description' />" +
                        "<FieldRef Name='Assignee' />" +
                    "</ViewFields>",
    CAMLQuery: "<Query><Where><Eq><FieldRef Name='ID' /><Value Type='Text'>" + id + "</Value></Eq></Where></Query>",
    completefunc: function (xData, Status) {
        $(xData.responseXML).SPFilterNode("z:row").each(function() { 
            id = $(this).attr("ows_ID");
            title = $(this).attr("ows_Title");
            description = $(this).attr("ows_Description");
            assignee = $(this).attr("ows_Assignee").split(";#");
            //some more formulas
        });
    }
});

我如何修改它来做同样的事情(从我的原始 SharePoint 列表中提取数据),但来自不同的网站集?

【问题讨论】:

    标签: javascript sharepoint sharepoint-2013 spservices cewp


    【解决方案1】:

    您可以尝试添加 webUrl 属性,如下所示:

    $().SPServices({
    webUrl: "https://sitecollectionUrl/"
    operation: 'GetListItems',
    async: false,
    listName: 'Requests',
    CAMLViewFields: "<ViewFields>" +
                        "<FieldRef Name='ID' />" +
                        "<FieldRef Name='Title' />" +
                        "<FieldRef Name='Description' />" +
                        "<FieldRef Name='Assignee' />" +
                    "</ViewFields>",
    CAMLQuery: "<Query><Where><Eq><FieldRef Name='ID' /><Value Type='Text'>" + id + "</Value></Eq></Where></Query>",
    completefunc: function (xData, Status) {
        $(xData.responseXML).SPFilterNode("z:row").each(function() { 
            id = $(this).attr("ows_ID");
            title = $(this).attr("ows_Title");
            description = $(this).attr("ows_Description");
            assignee = $(this).attr("ows_Assignee").split(";#");
            //some more formulas
        });
    }});
    

    https://itsharedspace.wordpress.com/2013/10/17/get-list-items-with-spservices/

    【讨论】:

    • 我尝试了很多不同的方法来让它工作,但代码没有运行。我在前面使用了带有 http:// 的 URL,我尝试将其取出,我将其设为 https://,但没有任何返回。我还需要做些什么才能使 webUrl 属性正常工作吗?如果我能让代码运行,这将是一个很好的解决方案。
    【解决方案2】:

    这就是我最终开始在我的第二个网站集上从第一个网站集提取数据的工作。我不得不用 ajax 重写所有的 SPServices:

    $.ajax({
        async: true,
        crossDomain: true,
        url: "http://sitecollectionUrl/_api/Web/Lists/GetByTitle('Requests')/Items$filter=startswith(ID, 'test')&$orderby=ID",
        method: "GET",
        headers: {
            "accept": "application/json;odata=verbose",
            "cache-control": "no-cache",
            "postman-token": "452d273c-96f4-d2a1-bd34-463ab627e4ab"
        },
        success: function (data) {
            $.each(data.d.results, function (index, item) {
                id = item.ID;
                title = item.Title;
                description = item.Description;
                //some more formulas
            });
        },
        complete: function (data) {
            //some more formulas
        }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多