Jos*_*osh 6 api sharepoint jquery
我正在对SP2013 doc库进行基本的OData/REST调用.我试图找到项目的URL,但无法确定如何执行此操作.我对服务器端对象模型非常熟悉,并且理解文件对象比项目更深一级.有人能指出我正确的方向或分享如何进入文件级别的文档?我已经搜索谷歌了.这是我的代码,仅用于访问doc库中的所有项目以及我希望定位的任何元数据列:
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
</html>
<script>
// workaround for access error
jQuery.support.cors = true;
// create REST query
var requestUri = "http://sp2013/_api/Web/Lists/getByTitle('Documents')/items";
// execute AJAX request
$.ajax({
url: requestUri,
type: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function(data){
alert(data.d.results);
$.each(data.d.results, function(index, item){
if (item["Meta1"] == null) {
$("body").append("<h1>No Title</h1>");
}
else {
$("body").append("<h1>" + item["Meta1"] + "</h1>");
}
});
},
error: function(jqXHR, textStatus, errorThrown){
alert(textStatus);
}
});
</script>
Run Code Online (Sandbox Code Playgroud)
ath*_*hom 14
对于完整的网址,请尝试:
"http://sp2013/_api/Web/Lists/getByTitle('Documents')/items?$select=EncodedAbsUrl"
Run Code Online (Sandbox Code Playgroud)
使用$ select query选项和FileRef
参数返回文档Url:
https://contoso.sharepoint.com/_api/web/lists/getbytitle('Documents')/items?$select=FileRef
Run Code Online (Sandbox Code Playgroud)
在SharePoint REST请求中使用OData查询操作
我认为您可以使用SharepointPlus来做到这一点 - 但它是第三方库。在文档中有这个例子:
// if you want to list all the files and folders for a Document Library
$SP().list("My Shared Documents").get({
fields:"BaseName,FileRef,FSObjType", // "BaseName" is the name of the file/folder; "FileRef" is the full path of the file/folder; "FSObjType" is 0 for a file and 1 for a folder (you need to apply $SP().cleanResult())
folderOptions:{
show:"FilesAndFolders_Recursive"
}
});
Run Code Online (Sandbox Code Playgroud)
至少这可以给你一些想法。
归档时间: |
|
查看次数: |
23125 次 |
最近记录: |