简体   繁体   English

如何使用JavaScript检索文档集的元数据

[英]How to retrieve metadata of document set using JavaScript

In my SharePoint site I have document sets with some metadata (Budget, Client Name, City ..). 在我的SharePoint网站中,我具有一些元数据(预算,客户端名称,城市..)的文档集。 I want to change the default look of doc-set homepage. 我想更改文档集首页的默认外观。 I want to retrieve the metadata of the current document set, show it in a content editor web part. 我想检索当前文档集的元数据,并在内容编辑器Web部件中显示它。

How do I retrieve current doc set metadata using JavaScript and based on the ID of the doc set? 如何使用JavaScript并基于文档集ID检索当前文档集元数据?

Using the Document Set Properties web part 使用文档集属性Web部件

First, keep in mind that there is already a web part that automatically displays metadata from the current document set. 首先,请记住,已经有一个Web部件可以自动显示当前文档集中的元数据。 This web part is called "Document Set Properties" and can be found in the "Document Sets" category of web parts. 该Web部件称为“文档集属性”,可以在Web部件的“文档集”类别中找到。

The fields that it displays can be configured by navigating to Library Settings, clicking the name of your Document Set content type under Content Types, and clicking "Document Set Settings." 可以通过导航到“库设置”,单击“内容类型”下的文档集内容类型的名称,然后单击“文档集设置”来配置它显示的字段。

Using REST or JSOM instead 改用REST或JSOM

If for some reason that web part is inadequate for your purposes, you can use the REST API or JavaScript client side object model to retrieve metadata about the current document set. 如果由于某种原因Web部件不足以实现您的目的,则可以使用REST API或JavaScript客户端对象模型来检索有关当前文档集的元数据。 You can obtain the ID of the current document set from the "ID" parameter in the query string section of the URL. 您可以从URL的查询字符串部分中的“ ID”参数获取当前文档集的ID。

SharePoint provides a handy GetUrlKeyValue() method to easily obtain query string parameters. SharePoint提供了一个便捷的GetUrlKeyValue()方法来轻松获取查询字符串参数。

REST 休息

var itemId = GetUrlKeyValue("ID");
var listGuid = GetUrlKeyValue("List");
var xhr = new XMLHttpRequest();
xhr.open("GET", "/_api/lists('"+listGuid+"')/items("+itemId+")");
xhr.setRequestHeader("accept","application/json;odata=verbose");
xhr.onreadystatechange = function(){
    if(xhr.readyState == 4){
        if(xhr.status == 200){
            var item = JSON.parse(xhr.responseText).d;
            var title = item.Title;
            var desc = item.DocumentSetDescription;
            // You can retrieve any other properties here as necessary
        }else{
           alert("error "+xhr.status+": "+xhr.responseText);
        }
    }
};
xhr.send();

JSOM JSOM

SP.SOD.ExecuteOrDelayUntilScriptLoaded(function(){
    var listGuid = GetUrlKeyValue("List");
    var itemId = GetUrlKeyValue("ID");
    var clientContext = new SP.ClientContext();
    var item = clientContext.get_web().get_lists().getById(listGuid).getItemById(itemId);
    clientContext.load(item);
    clientContext.executeQueryAsync(
        function(){
             var title = item.get_item("Title");
             var desc = item.get_item("DocumentSetDescription");
             // You can retrieve any other properties here as necessary
        },
        function(sender,args){
            alert(args.get_message());
        }
    );
},"sp.js");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Dynamics CRM中使用javascript检索已过滤的实体元数据 - How to Retrieve filtered metadata of entity using javascript in Dynamics CRM 如何使用 javascript 为 iframe 中的#document 设置焦点 - How to set focus for #document in iframe using javascript 如何使用 HMTL/Javascript 从 Firestore 数据库中的文档中检索数据 - How to retrieve data from document in Firestore db using HMTL/Javascript 如何使用Javascript通过URL链接检索MP3元数据? - How Can I retrieve MP3 metadata by a URL link using Javascript? 如何在 javascript 中的 azure 中将元数据设置为 createblockblobfrombrowserfile - How to set metadata to a createblockblobfrombrowserfile in azure in javascript 无法从SharePoint中的文档中检索javascript客户端对象模型中的文件夹中的元数据 - Can't retrieve metadata from a document in SharePoint inside a folder in javascript client object model 如何使用JavaScript设置非空值的Firestore文档字段 - How to set firestore document fields with non null values using javascript 如何使用 AWS Javascript SDK 从 AWS S3 存储桶中检索对象列表(包括与每个对象关联的元数据)? - How to retrieve list of objects (including the metadata associated with each object) from AWS S3 bucket using AWS Javascript SDK? 如何使用 Drive API 设置文件的元数据? - How to set the metadata of file using Drive API? 如何使用 Javascript 将自定义元数据添加到 Pdf - How to add Custom Metadata to Pdf using Javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM