0

我已经成功地使用 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 列表中提取数据),但来自不同的网站集?

4

2 回答 2

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/

于 2016-02-16T16:55:52.113 回答
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
    }
});
于 2016-03-09T22:53:25.507 回答