从另一个网站集中查询 SharePoint 2013 列表
Query SharePoint 2013 List from Another Site Collection
我已成功使用 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 列表中提取数据),但来自不同的网站集?
您可以尝试添加 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/
这就是我最终要从第一个网站集中提取第二个网站集的数据。我不得不用 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
}
});
我已成功使用 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 列表中提取数据),但来自不同的网站集?
您可以尝试添加 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/
这就是我最终要从第一个网站集中提取第二个网站集的数据。我不得不用 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
}
});