从另一个网站集查询SharePoint 2013列表

时间:2016-02-16 16:37:35

标签: javascript sharepoint sharepoint-2013 spservices cewp

我已成功使用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列表中提取数据),但是从其他网站集进行修改?

2 个答案:

答案 0 :(得分:0)

您可以尝试添加 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/

答案 1 :(得分:0)

这是我最终开始从第一个网站集中提取数据的工作。我不得不用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
    }
});