它不是一个完整的解决方案,您需要使用以下代码来解决问题,为了您的方便,我提供了一些链接。
这里是Link 很好很简单的文章,解释了如何使用 Rest api 和 AngularJS 在 SharePoint 2013 中获取列表数据。
Link 解释了如何使用 REST API 来通过 AngularJS 服务托管 Web。
$资源
angular.module('myApp.controllers',[]);
angular.module('myApp.controllers').controller('ResourceController',function($scope, Entry) {
var entry = Entry.get({ id: $scope.id }, function() {
console.log(entry);
}); // get() returns a single entry
var entries = Entry.query(function() {
console.log(entries);
}); //query() returns all the entries
$scope.entry = new Entry(); //You can instantiate resource class
$scope.entry.data = 'some data';
Entry.save($scope.entry, function() {
//data saved. do something here.
}); //saves an entry. Assuming $scope.entry is the Entry object
});
函数调用的结果是一个资源类对象,默认有以下方法:
get()
query()
save()
remove()
delete()
这里需要将以下 SharePoint REST API 与 ajax 结合起来
function get(url) {
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + url,
type: "GET",
headers: {
"accept": "application/json;odata=verbose",
},
success: function (data) {
console.log(data.d.results);
},
error: function (error) {
alert(JSON.stringify(error));
}
});
}
保存到 SharePoint 列表的方法
function save(url, data) {
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + url,
type: "POST",
headers: {
"accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"content-Type": "application/json;odata=verbose"
},
data: JSON.stringify(data),
success: function (data) {
console.log(data);
},
error: function (error) {
alert(JSON.stringify(error));
}
});
}
更新 SharePoint 列表中项目的方法
function update(url, oldItem, newItem) {
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + url,
type: "PATCH",
headers: {
"accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"content-Type": "application/json;odata=verbose",
"X-Http-Method": "PATCH",
"If-Match": oldItem.__metadata.etag
},
data: JSON.stringify(newItem),
success: function (data) {
console.log(data);
},
error: function (error) {
alert(JSON.stringify(error));
}
});
}
SharePoint 列表中删除项目的方法
function delete(url, oldItem) {
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + url,
type: "DELETE",
headers: {
"accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"If-Match": oldItem.__metadata.etag
},
success: function (data) {
},
error: function (error) {
alert(JSON.stringify(error));
}
});
}
列出 SharePoint 列表的示例代码
var employeesApp = angular.module(‘myApp’, []);
employeesApp.controller(’employeeCtrl’, function ($scope, $http) {
$http(
{
method: “GET”,
url: “/_api/web/lists/getByTitle(‘Employees’)/items”,
headers: { “Accept”: “application/json;odata=verbose” }
}
).success(function (data, status, headers, config) {
$scope.employees = data.d.results;
}).error(function (data, status, headers, config) {
alert(‘Error’);
});
});