简体   繁体   English

无法从SharePoint中的文档中检索javascript客户端对象模型中的文件夹中的元数据

[英]Can't retrieve metadata from a document in SharePoint inside a folder in javascript client object model

The below code is working fine for me when the document that contains the meta data isn't inside a folder. 当包含元数据的文档不在文件夹中时,下面的代码对我来说很好。 As soon as the document is placed into a folder in the document library it stops working after while (enumerator.moveNext()) { I've placed console.log in seperate lines in the code and that is the point at which i stop getting a response. 一旦将文档放入文档库中的文件夹中,它就会在while (enumerator.moveNext()) {之后停止工作while (enumerator.moveNext()) {我已将console.log放在代码中的单独行中,这就是我不再获取的地方一个答复。

I've created a new dispform.aspx called viewitem.aspx, and this js file is linked to it to pull the metadata out and display it in different divs on the page. 我创建了一个名为viewitem.aspx的新dispform.aspx,并将此js文件链接到它以将元数据拉出并在页面上的不同div中显示它。

below is the code: 以下是代码:

function getBody() {
    var context = new SP.ClientContext("https://xxx.sharepoint.com/sites/xxx");
    var list = context.get_web().get_lists().getByTitle('Docs');
    JSRequest.EnsureSetup();
    var listItemId = GetUrlKeyValue("ID");
    var item = new SP.CamlQuery();
    item.set_viewXml("<View><Query><Where><Eq><FieldRef Name='ID'/><Value Type='Number'>" + listItemId + "</Value></Eq></Where></Query></View>");
    returnedItemsBE1 = list.getItems(item);
    context.load(returnedItemsBE1);
    context.executeQueryAsync(onSucceededCallbackBE1);
        }
        function onSucceededCallbackBE1() {
            var enumerator = returnedItemsBE1.getEnumerator();
            while (enumerator.moveNext()) {
                var listItem = enumerator.get_current();
                var tmbod = listItem.get_item('TmBody');
                var tmfile = listItem.get_item('TmAttachmentTitle');
                var tmId = listItem.get_item('TmTransID');
                var tmfileurl = 'https://xxx.sharepoint.com/sites/xxx/Docs/'+tmId+'_'+tmfile;
                document.getElementById("fileLink").href = tmfileurl;
                document.getElementById("fileLink").innerText = tmfile ;                                    
                var bdiv = document.getElementById("bodyDiv");
                bdiv.innerHTML = tmbod;
                    }                                           
                }                               

` `

I'm using SharePoint 2013 online, I can't figure out how the item being in a folder can make any difference, the URL changes but it still contains the file ID etc... 我在线使用SharePoint 2013,我无法弄清楚文件夹中的项目如何有所不同,URL更改但它仍然包含文件ID等...

I've searched and searched and can't find any reference to this, any help would be appreciated! 我搜索和搜索,找不到任何参考,任何帮助将不胜感激!

Try using Scope='Recursive' in you View tag. 尝试在View标签中使用Scope='Recursive' Else, it will only get the files in the given directory. 否则,它只会获取给定目录中的文件。

item.set_viewXml("<View Scope='Recursive'><Query><Where><Eq><FieldRef Name='ID'/><Value Type='Number'>" + listItemId + "</Value></Eq></Where></Query></View>");

There are four view scopes: 有四个视图范围:

  • Default (no Scope given): retrieve all the files in the current folder 默认(未给出范围):检索当前文件夹中的所有文件

  • All: retrieve files and folders in the current folder 全部:检索当前文件夹中的文件和文件夹

  • Recursive: retrieve files in the current folder and its sub-folders, and in their sub-folders, etc. 递归:检索当前文件夹及其子文件夹及其子文件夹中的文件等。

  • RecursiveAll: same as Recursive, but also retrieves the sub-folders. RecursiveAll:与Recursive相同,但也检索子文件夹。

I found this handy page if a visual explanation works better for you. 如果视觉解释更适合您,我找到了这个方便的页面

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

相关问题 如何使用Javascript客户端对象模型检索Sharepoint 2010列表项权限 - How to retrieve Sharepoint 2010 list item permissions using Javascript Client Object Model 如何使用JavaScript的客户端对象模型在共享点列表中检索超链接数据类型列的值 - How to retrieve hyperlink data type column value in sharepoint list using client object model of javascript SharePoint 2013 JavaScript客户端对象模型 - SharePoint 2013 JavaScript Client Object Model 无法从Javascript检索RadDatePicker对象 - Can't retrieve RadDatePicker object from Javascript 如何在Sharepoint 2013客户端对象模型中使用javascript getPeerUrl()函数? - How to use the javascript getPeerUrl() function in Sharepoint 2013 client object model? JavaScript客户端对象模型中的SharePoint 2010 SP.FileCreationInformation() - SharePoint 2010 SP.FileCreationInformation() in javascript client object model 是否有可用于SharePoint 2010的基于JavaScript的客户端对象模型的API? - Is there an API available for SharePoint 2010's JavaScript based Client Object Model? 如何使用JavaScript检索文档集的元数据 - How to retrieve metadata of document set using JavaScript 使用JavaScript从C#中检索sharepoint对象列表 - Retrieve sharepoint object list from C# using JavaScript 无法在Javascript中检索对象属性 - Can't retrieve object property in Javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM