使用角度js

时间:2016-12-13 14:38:57

标签: angularjs sharepoint-2013 office365

我想使用Angular js和REST api开发一个最近的文档小部件。 这是我的代码:

    var spApp= angular.module('spng-App', []);  
    spApp.controller('spng-WebCtrl', function($scope, $http){  

        $http({  
            method: "GET",  
            url:_spPageContextInfo.webAbsoluteUrl+"/_api/web/Lists/GetByTitle('Docwidget')/items?$select=Title,ID",  
            headers: {"Accept":"application/json;odata=verbose"}  
        }).success(function(Folderdata, status, headers, config){   
            $scope.Folders= Folderdata.d.results;   
        }).error(function (Folderdata, status, headers, config){  

        });         
    });  
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" >

<!-- Appel au fichiers JS -->
    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>  
    <script type="text/javascript" src="/sites/Publishing/_catalogs/masterpage/Devcollabshareapp/app_test_Docs/ControlDocs.js"></script>
<!-- Fin Appel au fichiers JS -->


<style type="text/css">  
.files-table th{ background-color:#ddd; border:2px solid #fff; text-align:left}  
.files-table td{ background-color:#eee; border:2px solid #fff;}  
.web-heading{ padding:2px;}  
</style> 

</head>

<body>


<div ng-app="spng-App">  
<div ng-controller="spng-WebCtrl">

    <!-- Populate Files based on selected Folder -->  
    <table width="100%" cellpadding="10" cellspacing="2" class="files-table">  

            <tr>  
                <th>Title</th>  
                <th>ID</th>   
            </tr>  

            <tr ng-repeat="Folder in Folders">  
                <td><a href="{{Folder.ServerRelativeUrl}}">{{Folder.Title}}</a></td>  
                <td>{{Folder.Id}}</td>   
            </tr>  

    </table>  

</div>  
</div>

</body>
</html>

我在Sharepoint 2013上有一个名为“Docwidget”的库,我想恢复它包含的文件。在那之前,我会检索标题和标识,而不是其他细节,此外,当我点击文件时,它不会打开。恢复文件的URL有问题吗?如果没有其他提案?

2 个答案:

答案 0 :(得分:1)

请尝试使用&#34; _api / Web / GetFolderByServerRelativeUrl(&#39; / Docwidget&#39;)/ files?$ select =作者/ ID,作者/姓名,作者/标题,ServerRelativeUrl&amp; $扩大=作者&#34;

它会给你&#34; ServerRelativeUrl &#34;。

请参阅以下屏幕截图,了解我从这两方面获得的REST响应。

<强> 1。 _api / Web / Lists / getbytitle(&#39;文档库名称&#39;)/ items

enter image description here

<强> 2。 _api /网络/ GetFolderByServerRelativeUrl(&#39; folderRelativeUrl&#39;)/文件 enter image description here

第3。 _api /网络/ GetFolderByServerRelativeUrl(&#39; folderRelativeUrl&#39;)/文件$选择=作者/编号,作者/名称,作者/标题,ServerRelativeUrl和放大器; $展开;作者 enter image description here

答案 1 :(得分:0)

使用此代码很有用:"/_api/web/GetFolderByServerRelativeUrl('/sites/Publishing/d‌​ocwidget')/Files"。现在我想添加文件的其他详细信息:作者,创建日期,更改为......我还需要其他查询吗?因为这个请求<td>{{Folder.Author}}</td>我收到的结果是{{.../_api/Web/GetFileByServerRelativeUrl('/sites/Publishing/docwidget/spring.docx')/Author"}}而不是作者的名字?