[英]Angularjs Sharepoint Rest API to showing all columns
I have created a very basic controller to pull data from a SharePoint list, but it only pulls the base Title and created column. 我已经创建了一个非常基本的控制器来从SharePoint列表中提取数据,但是它仅提取基本的Title和created列。 It doesn't pull any columns I have created, which are the ones I require.
它不会拉出我创建的任何列,而这正是我需要的列。 Is there a setting in SP itself to state it is available for the API?
SP本身是否有设置可以声明可用于API?
I have used the code off this site: http://www.c-sharpcorner.com/article/retrieve-sharepoint-list-items-using-angularjs-with-single-a/ 我已经在以下站点使用过代码: http : //www.c-sharpcorner.com/article/retrieve-sharepoint-list-items-using-angularjs-with-single-a/
As shown here: 如此处所示:
var appVar = angular.module('listApp', []); appVar.controller("controller1", function($scope){ GetListItems($scope, "List1"); }); function GetListItems($scope, listName){ $.ajax({ url: "https://example.com/sites/mysite/_api/web/lists/GetByTitle('"+listName+"')/items", method: "GET", async: false, headers: { "Accept": "application/json;odata=verbose" }, success: function(data){ $scope.items = data.d.results; }, error: function(sender,args){ console.log(args.get_message()); } }); }
<div ng-app="listApp"> <div id="App1" ng-controller="controller1"> <h1>First List Items</h1> <div ng-repeat="item in items"> <p>{{item.Title}}</p> </div> </div> </div>
SP.ListItemCollection
resource endpoint SP.ListItemCollection
资源端点
/_api/web/lists/getByTitle('<list title>')/items
returns all the field values for a list items with some limitation for User/Lookup fields (for performance reasons): 返回列表项的所有字段值,但对“用户/查找”字段有一些限制(出于性能原因):
In case of User/Lookup fields only lookup ids will be retrieved by default.
如果是“用户/查找”字段,则默认情况下将仅检索查找ID。
In your example only SP.ListItem.Title
property is printed, if you want to display all the returned list item values it could be accomplished like this: 在您的示例中,仅打印
SP.ListItem.Title
属性,如果要显示所有返回的列表项值,可以这样完成:
<div ng-repeat="item in items">
<p>{{item.Title}}</p>
<p ng-repeat="(key, value) in item">
{{ value }}
</p>
</div>
Some another suggestions: 其他一些建议:
jQuery.ajax()
in Angular apps jQuery.ajax()
$ http服务而不是jQuery.ajax()
Example 例
<div ng-app="spApp" ng-controller="TasksController" >
<table>
<tr ng-repeat="t in tasks">
<td ng-repeat="(key, value) in t" ng-if="!value.hasOwnProperty('__deferred') && !value.hasOwnProperty('__metadata')">
{{ value }}
</td>
</tr>
</table>
</div>
Controller 控制者
angular.module('spApp',[])
.controller('TasksController', function($scope,$http) {
$scope.tasks = [];
$scope.getListItems = function(listTitle) {
return $http({
method : 'GET',
url : _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('" + listTitle + "')/items",
headers: { 'Accept':'application/json;odata=verbose' }
});
}
$scope.getListItems("Tasks")
.success(function(data, status) {
$scope.tasks = data.d.results;
})
.error(function(data, status) {
console.log("An error occured");
});
});
Just to shed some light further on this, I have noticed that the original pull was in fact bringing all my columns, but they were shown as Static names, not the Display name, so I was unable to first decipher them when showing the whole scope. 只是为了进一步阐明这一点,我注意到原始的拉扯实际上是在带我的所有列,但是它们显示为静态名称,而不是显示名称,因此在显示整个范围时,我无法首先对其进行解密。
With this, I am able to view via the ng-repeat using the internal reference. 这样,我可以使用内部参考通过ng-repeat进行查看。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.