С:
import { SPHttpClient, SPHttpClientResponse, ISPHttpClientOptions } from '@microsoft/sp-http';
И дано:
List: List1
и
View: View1
Это SPFX Код API REST:
const executeJson = (endpointUrl, payload) => {
const opt: ISPHttpClientOptions = { method: 'GET' };
if (payload) {
opt.method = 'POST';
opt.body = JSON.stringify(payload);
}
return this.context.spHttpClient.fetch(endpointUrl, SPHttpClient.configurations.v1, opt);
};
const getListItems = (webUrl,listTitle, queryText) => {
var viewXml = '<View><Query>' + queryText + '</Query></View>';
var endpointUrl = webUrl + "/_api/web/lists/getbytitle('" + listTitle + "')/getitems";
var queryPayload = {'query' : { 'ViewXml' : viewXml } };
return executeJson(endpointUrl, queryPayload);
};
const getListViewItems = (webUrl,listTitle,viewTitle) => {
var endpointUrl = webUrl + "/_api/web/lists/getByTitle('" + listTitle + "')/Views/getbytitle('" + viewTitle + "')/ViewQuery";
return executeJson(endpointUrl, null).then((response: SPHttpClientResponse) => { return response.json(); })
.then(data => {
var viewQuery = data.value;
return getListItems(webUrl,listTitle,viewQuery);
});
};
const url = this.context.pageContext.site.absoluteUrl;
getListViewItems(url,'List1','View1')
.then((response: SPHttpClientResponse) => { return response.json(); })
.then(response=>{
for (var item of response.value) {
console.log(item);
}
});
выведет элементы представления списка на консоль.
Спасибо: Ответ Вадима Гремячева на SharePoint 2013