尝试使用 Graph api 从 SharePoint Online 库中获取自定义字段的值

Trying to get a value of custom field from a SharePoint Online library using Graph api

我在显示 SharePoint Online 文档库中的自定义字段时遇到问题。我能够查看所有字段。我能够显示一个系统字段,但是当我尝试只显示某个自定义字段时它没有显示。

下面是我的代码。如果我需要更清楚,请告诉我。

谢谢!

HTML

<div graph-data-retriever url="https://example.com/sites/stage/_api/Web/GetFolderByServerRelativeUrl('MainFolder/SubFolder')/Files?$expand=ListItemAllFields">      
<div ng-repeat="item in graphData.result.value">    

{{item}} <!-- Shows all fields and values, including the custom field I'm trying to display - "CustomField" -->
{{item.Title}} <!-- Shows the Title of the document -->
{{item.Name}} <!-- Shows the Name of the document -->
{{item.CustomField}}  <!-- Doesn't display the value of CustomField -->   

</div>
</div>

graphDataRetriever.directive

angular.module('abc.components').directive('graphDataRetriever', function () {
    return {
        restrict: "A",
        bindToController: {
            url: "@",
            verb: "@",
            data: "<"
        },
        controllerAs: "graphData",
        controller: ["$scope", '$timeout', 'graphService', function ($scope, $timeout, graphService) {

            var ctrl = this;
            $scope.$watch('url', loadContent);

            function loadContent() {
                ctrl.result = {};
                ctrl.loading = true;

                graphService.http(ctrl.url, ctrl.verb, ctrl.data).then(success, failed);

                function success(response) {
                    ctrl.result = response;
                    ctrl.loading = false;
                }
                function failed(e) {
                    ctrl.loading = false;
                }
            }           
        }]
    };
});

graphService.service

angular.module('abc.services').service('graphService', ['proxyService', '$q', function (proxyService, $q) {
    var makeReq = function (url, verb, data, headers) {
        var deferred = $q.defer();
        var request = new proxyService.requestPayload(url);
        if (headers) {
            angular.forEach(headers, function (item) {
                request.addHeader(item.key, item.value);
            });
        } else {
            request.addHeader('Content-Type', 'application/json');
            request.addHeader('Accept', 'application/json');
        }

        if(data) {
            request.body = data;
        }
        request.httpVerb = verb || 'GET';

        function success(response) {
            var parsed = angular.fromJson(response);
            deferred.resolve(parsed);
        }
        function failed(e) {
            deferred.reject(e);
        }

        proxyService.azureRequest(request).then(success, failed);

        return deferred.promise;
    }

    return  {
        http: function (url, verb, data, headers) {
            return makeReq(url,verb,data,headers);
        },
        get: function (url, data, headers) {
            return makeReq(url, 'GET', data, headers);
        },
        post: function (url, data, headers) {
            return makeReq(url, 'POST', data, headers);
        }
    }
}]);



尝试

 {{item.ListItemAllFields.CustomField}}

您可以使用 fiddler 来监控返回的 JSON 数据。