簡體   English   中英

如何通過在SharePoint2013中使用angularJS登錄的用戶篩選列表結果

[英]How do I filter my list results by the user logged on using angularJS in SharePoint2013

這是我第一次發布問題,請原諒我的無知。

概述 :我當前正在使用REST拉取來拉回SharePoint 2013列表數據以返回JSON數據。 以下是我的JS和HTML。

問題 :我需要過濾數據以僅顯示由登錄用戶創建的項目。我要處理的最終結果是一個頁面,其中僅由登錄用戶創建的項目顯示在表格中。

JS

    var myAngApp = angular.module('SharePointAngApp', []);   
    myAngApp.controller('spCustomerController', function ($scope, $http){   
        $http({
            method: 'GET',   
            url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('ITEquipmentRequests')/items?$select=*",   
            headers: { "Accept": "application/json;odata=verbose"}   
            }).success(function (data, status, headers, config) {
        $scope.customers = data.d.results;
    }).error(function (data, status, headers, config) {
    });
});

HTML

<div ng-controller="spCustomerController">   

    <table id="requestTable" class="table table-hover table-bordered"> 

        <tr id="requestTableHeader">   
            <th>Name</th>
            <th>Supervisor</th>
            <th>Section Chief</th>
            <th>ISO</th>
            <th>Pentad</th>
            <th>FCIO</th>
            <th>Status</th> 
        </tr>

        <tr ng-repeat="customer in customers">   
            <td class="col-md-4"><a ng-href="/PHX_IRM/ITEquip/ITEquipmentRequests/{{customer.Title}}">{{customer.Title}}</a></td>
            <td class="col-md-1"><img class="statusIcon" src="{{customer.TextPicture}}" alt="Status"></td>
            <td class="col-md-1"><img class="statusIcon" src="{{customer.SectionChief}}" alt="Status"></td>
            <td class="col-md-1"><img class="statusIcon" src="{{customer.ISO}}" alt="Status"></td>
            <td class="col-md-1"><img class="statusIcon" src="{{customer.Pentad}}" alt="Status"></td>
            <td class="col-md-1"><img class="statusIcon" src="{{customer.FCIO}}" alt="Status"></td>
            <td class="col-md-2">{{customer.Status}}</td>
        </tr>   
    </table>
</div>   

任何幫助將不勝感激。 感謝您的時間。

如果要在客戶端過濾結果,可以在中繼器中使用角度過濾器。

<tr ng-repeat="customer in customers | filter : customer == loggedInUser">   

您可以考慮以下選項:

通過CAML查詢過濾列表項

通過CAML查詢過濾列表項。 服務器將僅返回滿足查詢條件的項目,為此目的將替換請求:

$http({
       method: 'GET',   
       url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('ITEquipmentRequests')/items?$select=*",   
       headers: { "Accept": "application/json;odata=verbose"}   
}) 

//request endpoint
var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('" + listTitle + "')/getitems";
//construct CAML query to return list items created by current user
var queryXml = "<View><Query><Where><Eq><FieldRef Name='Author' LookupId='True'/><Value Type='Lookup'>" + _spPageContextInfo.userId + "</Value></Eq></Where></Query></View>";
//query payload
var queryPayload = { 
   'query':{ 
       '__metadata': { 'type': 'SP.CamlQuery' },
       'ViewXml': queryXml
    } 
}; 



$http({
       method: "POST",
       url : endpointUrl,
       data: queryPayload,  
       headers: {
               "Content-Type" : "application/json;odata=verbose",
               "Accept": "application/json;odata=verbose",
               "X-RequestDigest": document.getElementById('__REQUESTDIGEST').value 
       }          
}) 

說明:

使用以下端點通過POST請求調用CAML查詢:

/_api/web/lists/getbytitle('<listTitle>')/getitems

從性能的角度來看,它代表了最佳方法。

使用角度filter

替換行:

<tr ng-repeat="customer in customers">

<tr ng-repeat="customer in customers | filter : isCurrentCustomer"> 

並在控制器中聲明isCurrentCustomer函數,如下所示:

$scope.isCurrentCustomer = function(customer){
    return (customer.AuthorId == _spPageContextInfo.userId);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM