【发布时间】:2014-11-02 21:11:39
【问题描述】:
如何使用 REST API 获取 SharePoint 列表的不同列数据? 有没有办法在不循环的情况下实现它?
谢谢!
【问题讨论】:
-
问之前最好做一些研究,因为这不是一个教程网站
标签: jquery sharepoint sharepoint-online
如何使用 REST API 获取 SharePoint 列表的不同列数据? 有没有办法在不循环的情况下实现它?
谢谢!
【问题讨论】:
标签: jquery sharepoint sharepoint-online
根据Use OData query operations in SharePoint REST requests,不支持grouping等操作。
解决方案是在从 SharePoint REST 服务返回 JSON 结果之后应用分组。
function groupBy(items,propertyName)
{
var result = [];
$.each(items, function(index, item) {
if ($.inArray(item[propertyName], result)==-1) {
result.push(item[propertyName]);
}
});
return result;
}
var catalog = { products: [
{ category: "Food & Dining"},
{ category: "Techonology"},
{ category: "Retail & Apparel"},
{ category: "Retail & Apparel"}
]};
var categoryNames = groupBy(catalog.products, 'category'); //get distinct categories
console.log(categoryNames);
假设以下函数用于通过 SharePoint REST API 获取列表项:
function getListItems(url, listname, query, complete, failure) {
$.ajax({
url: url + "/_api/web/lists/getbytitle('" + listname + "')/items" + query,
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
complete(data.d);
},
error: function (data) {
failure(data);
}
});
}
那么下面的例子演示了如何打印不同的任务名称:
getListItems('https://tenant.sharepoint.com/project','Tasks','?select=Title',
function(items){
var taskNames = groupBy(items,'Title');
console.log(taskNames);
},
function(error){
console.log(JSON.stringify(error));
}
);
【讨论】:
据我了解,您说的是 http:///_vti_bin/Lists.asmx。
嗯,是的,你应该可以通过简单的 SQL 来查询数据——选择 Distinct...
我一直在为用户 Web 服务使用相同的概念。但是,它只是给你一个线索。
参考:http://msdn.microsoft.com/en-us/library/office/ms429658(v=office.14).aspx
【讨论】: